diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 2003-10-07 23:37:28 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 2003-10-07 23:37:28 +0000 |
commit | 593cffe70c61f5b8345c5455233c0082b7b5b850 (patch) | |
tree | 4dbcd0525097207a989287f628df23dc80ddd99c /usr.bin | |
parent | 6628301891a6c202158f8acdda10d750a0e71cbc (diff) |
Fix printing of "Only in foo" when foo is "/" (trailing slash removal
was overzealous in this case). Fix tested by Hugo Villeneuve and myself.
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/diff/diff.c | 16 | ||||
-rw-r--r-- | usr.bin/diff/diff.h | 3 | ||||
-rw-r--r-- | usr.bin/diff/diffdir.c | 10 |
3 files changed, 17 insertions, 12 deletions
diff --git a/usr.bin/diff/diff.c b/usr.bin/diff/diff.c index aef4b781234..5fa299fa73f 100644 --- a/usr.bin/diff/diff.c +++ b/usr.bin/diff/diff.c @@ -1,4 +1,4 @@ -/* $OpenBSD: diff.c,v 1.42 2003/09/07 22:05:30 millert Exp $ */ +/* $OpenBSD: diff.c,v 1.43 2003/10/07 23:37:27 millert Exp $ */ /* * Copyright (c) 2003 Todd C. Miller <Todd.Miller@courtesan.com> @@ -21,7 +21,7 @@ */ #ifndef lint -static const char rcsid[] = "$OpenBSD: diff.c,v 1.42 2003/09/07 22:05:30 millert Exp $"; +static const char rcsid[] = "$OpenBSD: diff.c,v 1.43 2003/10/07 23:37:27 millert Exp $"; #endif /* not lint */ #include <sys/param.h> @@ -339,13 +339,19 @@ push_excludes(char *pattern) } void +print_only(const char *path, size_t dirlen, const char *entry) +{ + if (dirlen > 1) + dirlen--; + printf("Only in %.*s: %s\n", (int)dirlen, path, entry); +} + +void print_status(int val, char *path1, char *path2, char *entry) { switch (val) { case D_ONLY: - /* must strip off the trailing '/' */ - printf("Only in %.*s: %s\n", (int)(strlen(path1) - 1), - path1, entry); + print_only(path1, strlen(path1), entry); break; case D_COMMON: printf("Common subdirectories: %s%s and %s%s\n", diff --git a/usr.bin/diff/diff.h b/usr.bin/diff/diff.h index d950fe9b435..17b008281da 100644 --- a/usr.bin/diff/diff.h +++ b/usr.bin/diff/diff.h @@ -1,4 +1,4 @@ -/* $OpenBSD: diff.h,v 1.23 2003/08/01 20:54:18 deraadt Exp $ */ +/* $OpenBSD: diff.h,v 1.24 2003/10/07 23:37:27 millert Exp $ */ /*- * Copyright (c) 1991, 1993 @@ -81,4 +81,5 @@ int easprintf(char **, const char *, ...); void *emalloc(size_t); void *erealloc(void *, size_t); void diffdir(char *, char *); +void print_only(const char *, size_t, const char *); void print_status(int, char *, char *, char *); diff --git a/usr.bin/diff/diffdir.c b/usr.bin/diff/diffdir.c index a7e3df88121..dcdcf41a542 100644 --- a/usr.bin/diff/diffdir.c +++ b/usr.bin/diff/diffdir.c @@ -1,4 +1,4 @@ -/* $OpenBSD: diffdir.c,v 1.24 2003/07/21 23:28:00 millert Exp $ */ +/* $OpenBSD: diffdir.c,v 1.25 2003/10/07 23:37:27 millert Exp $ */ /* * Copyright (c) 2003 Todd C. Miller <Todd.Miller@courtesan.com> @@ -21,7 +21,7 @@ */ #ifndef lint -static const char rcsid[] = "$OpenBSD: diffdir.c,v 1.24 2003/07/21 23:28:00 millert Exp $"; +static const char rcsid[] = "$OpenBSD: diffdir.c,v 1.25 2003/10/07 23:37:27 millert Exp $"; #endif /* not lint */ #include <sys/param.h> @@ -118,8 +118,7 @@ diffdir(char *p1, char *p2) else if (lflag) dent1->d_status |= D_ONLY; else - printf("Only in %.*s: %s\n", (int)(dirlen1 - 1), - path1, dent1->d_name); + print_only(path1, dirlen1, dent1->d_name); dp1++; } else { /* file only in second dir, only diff if -N or -P */ @@ -128,8 +127,7 @@ diffdir(char *p1, char *p2) else if (lflag) dent2->d_status |= D_ONLY; else - printf("Only in %.*s: %s\n", (int)(dirlen2 - 1), - path2, dent2->d_name); + print_only(path2, dirlen2, dent2->d_name); dp2++; } } |