diff options
author | des <des@FreeBSD.org> | 2000-09-06 07:28:02 +0000 |
---|---|---|
committer | des <des@FreeBSD.org> | 2000-09-06 07:28:02 +0000 |
commit | 4cb6e07eff50cdac3f7749db23fbc6e2027d314f (patch) | |
tree | 4da8669e3a2cd66314db06abd2a235062b9df5b0 /usr.bin | |
parent | 96866cfa2a69b7cf5a7492ae65aff72e5e6eb5b1 (diff) | |
download | FreeBSD-src-4cb6e07eff50cdac3f7749db23fbc6e2027d314f.zip FreeBSD-src-4cb6e07eff50cdac3f7749db23fbc6e2027d314f.tar.gz |
Reintroduce functionality and error checks that were boneheadedly removed
in the previous commit. Pass me the pointy hat.
PR: bin/21061
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/basename/basename.c | 9 | ||||
-rw-r--r-- | usr.bin/dirname/dirname.c | 6 |
2 files changed, 13 insertions, 2 deletions
diff --git a/usr.bin/basename/basename.c b/usr.bin/basename/basename.c index d807ed9..e22e5a6 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); } diff --git a/usr.bin/dirname/dirname.c b/usr.bin/dirname/dirname.c index cb5adbd..f9d3e3d 100644 --- a/usr.bin/dirname/dirname.c +++ b/usr.bin/dirname/dirname.c @@ -43,6 +43,7 @@ static const char copyright[] = static const char sccsid[] = "@(#)dirname.c 8.4 (Berkeley) 5/4/95"; #endif /* not lint */ +#include <err.h> #include <libgen.h> #include <stdio.h> #include <unistd.h> @@ -54,6 +55,7 @@ main(argc, argv) int argc; char **argv; { + char *p; int ch; while ((ch = getopt(argc, argv, "")) != -1) @@ -68,7 +70,9 @@ main(argc, argv) if (argc != 1) usage(); - (void)printf("%s\n", dirname(*argv)); + if ((p = dirname(*argv)) == NULL) + err(1, "%s", *argv); + (void)printf("%s\n", p); exit(0); } |