[hackers] [sbase] enmasse same file check || Connor Lane Smith

From: <hg_AT_suckless.org>
Date: Thu, 23 Jun 2011 00:05:20 +0200 (CEST)

changeset: 91:0cc176955187
tag: tip
user: Connor Lane Smith <cls_AT_lubutu.com>
date: Wed Jun 22 23:04:56 2011 +0100
files: util/enmasse.c
description:
enmasse same file check

diff -r 3f408c4419e7 -r 0cc176955187 util/enmasse.c
--- a/util/enmasse.c Tue Jun 21 05:05:37 2011 +0100
+++ b/util/enmasse.c Wed Jun 22 23:04:56 2011 +0100
@@ -7,6 +7,8 @@
 #include <sys/stat.h>
 #include "../util.h"
 
+static void fnck(const char *, const char *, int (*)(const char *, const char *));
+
 void
 enmasse(int argc, char **argv, int (*fn)(const char *, const char *))
 {
@@ -16,8 +18,7 @@
         struct stat st;
 
         if(argc == 2 && !(stat(argv[1], &st) == 0 && S_ISDIR(st.st_mode))) {
- if(fn(argv[0], argv[1]) == -1)
- eprintf("%s:", argv[1]);
+ fnck(argv[0], argv[1], fn);
                 return;
         }
         else if(argc == 1)
@@ -31,8 +32,19 @@
                 eprintf("malloc:");
         for(i = 0; i < argc; i++) {
                 snprintf(buf, size, "%s/%s", dir, basename(argv[i]));
- if(fn(argv[i], buf) == -1)
- eprintf("%s:", buf);
+ fnck(argv[i], buf, fn);
         }
         free(buf);
 }
+
+void
+fnck(const char *a, const char *b, int (*fn)(const char *, const char *))
+{
+ struct stat sta, stb;
+
+ if(stat(a, &sta) == 0 && stat(b, &stb) == 0
+ && sta.st_dev == stb.st_dev && sta.st_ino == stb.st_ino)
+ eprintf("%s: same file as: %s\n", b, a);
+ if(fn(a, b) == -1)
+ eprintf("%s:", b);
+}
Received on Thu Jun 23 2011 - 00:05:20 CEST

This archive was generated by hypermail 2.2.0 : Thu Jun 23 2011 - 00:12:05 CEST