summaryrefslogtreecommitdiffstats
path: root/usr.bin/basename
diff options
context:
space:
mode:
authordes <des@FreeBSD.org>2000-09-06 07:28:02 +0000
committerdes <des@FreeBSD.org>2000-09-06 07:28:02 +0000
commit4cb6e07eff50cdac3f7749db23fbc6e2027d314f (patch)
tree4da8669e3a2cd66314db06abd2a235062b9df5b0 /usr.bin/basename
parent96866cfa2a69b7cf5a7492ae65aff72e5e6eb5b1 (diff)
downloadFreeBSD-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/basename')
-rw-r--r--usr.bin/basename/basename.c9
1 files changed, 8 insertions, 1 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);
}
OpenPOWER on IntegriCloud