diff options
author | Dag-Erling Smørgrav <des@FreeBSD.org> | 2000-09-06 07:28:02 +0000 |
---|---|---|
committer | Dag-Erling Smørgrav <des@FreeBSD.org> | 2000-09-06 07:28:02 +0000 |
commit | 0de750cfc832491227f2804fcc23296f367a7b96 (patch) | |
tree | 1036cc2f026c6bcd955389acf22731f283832ea3 /usr.bin/basename | |
parent | 6b6821c77185758431e5ec20eba332b9ba45b2c8 (diff) | |
download | src-0de750cfc832491227f2804fcc23296f367a7b96.tar.gz src-0de750cfc832491227f2804fcc23296f367a7b96.zip |
Reintroduce functionality and error checks that were boneheadedly removed
in the previous commit. Pass me the pointy hat.
PR: bin/21061
Notes
Notes:
svn path=/head/; revision=65508
Diffstat (limited to 'usr.bin/basename')
-rw-r--r-- | usr.bin/basename/basename.c | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/usr.bin/basename/basename.c b/usr.bin/basename/basename.c index d807ed9a86e6..e22e5a6c4a2a 100644 --- a/usr.bin/basename/basename.c +++ b/usr.bin/basename/basename.c @@ -43,8 +43,10 @@ static const char copyright[] = static const char sccsid[] = "@(#)basename.c 8.4 (Berkeley) 5/4/95"; #endif /* not lint */ +#include <err.h> #include <libgen.h> #include <stdio.h> +#include <string.h> #include <unistd.h> void usage __P((void)); @@ -54,6 +56,7 @@ main(argc, argv) int argc; char **argv; { + char *p, *q; int ch; while ((ch = getopt(argc, argv, "")) != -1) @@ -68,7 +71,11 @@ main(argc, argv) if (argc != 1 && argc != 2) usage(); - (void)printf("%s\n", basename(*argv)); + if ((p = basename(argv[0])) == NULL) + err(1, "%s", argv[0]); + if (*++argv && (q = strstr(p, *argv)) && strcmp(q, *argv) == 0) + *q = '\0'; + (void)printf("%s\n", p); exit(0); } |