sbase

suckless unix tools
git clone git://git.2f30.org/sbase
Log | Files | Refs | README | LICENSE

commit 2835d9ecda6a5d6b40f972ff5d6a11c0af155139
parent d7f9bda740158ff87340798b06ebf412b90ceda1
Author: Connor Lane Smith <cls@lubutu.com>
Date:   Wed, 22 Jun 2011 23:04:56 +0100

enmasse same file check
Diffstat:
Mutil/enmasse.c | 20++++++++++++++++----
1 file changed, 16 insertions(+), 4 deletions(-)

diff --git a/util/enmasse.c b/util/enmasse.c @@ -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 @@ enmasse(int argc, char **argv, int (*fn)(const char *, const char *)) 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 @@ enmasse(int argc, char **argv, int (*fn)(const char *, const char *)) 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); +}