diff options
author | des <des@FreeBSD.org> | 2000-10-12 16:22:15 +0000 |
---|---|---|
committer | des <des@FreeBSD.org> | 2000-10-12 16:22:15 +0000 |
commit | 51c91a72d927ac55e028218db79ad05e1c0e9853 (patch) | |
tree | 9d3cd1c7b67deac78ce267687c8498c88d360fbc | |
parent | b258f7d986b12b8f2e081344ec4f7c0d76d5c366 (diff) | |
download | FreeBSD-src-51c91a72d927ac55e028218db79ad05e1c0e9853.zip FreeBSD-src-51c91a72d927ac55e028218db79ad05e1c0e9853.tar.gz |
Fix suffix matching.
Restore historical behaviour when the first argument is an empty string.
Submitted by: Alexander N. Kabaev <ak03@gte.com>
Pointed out by: bde
-rw-r--r-- | usr.bin/basename/basename.c | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/usr.bin/basename/basename.c b/usr.bin/basename/basename.c index e22e5a6..b6756ca 100644 --- a/usr.bin/basename/basename.c +++ b/usr.bin/basename/basename.c @@ -71,10 +71,15 @@ main(argc, argv) if (argc != 1 && argc != 2) usage(); + if (!*argv[0]) { + printf("\n"); + exit(0); + } if ((p = basename(argv[0])) == NULL) err(1, "%s", argv[0]); - if (*++argv && (q = strstr(p, *argv)) && strcmp(q, *argv) == 0) - *q = '\0'; + if (*++argv && (q = strchr(p, '\0') - strlen(*argv)) > p && + strcmp(*argv, q) == 0) + *q = '\0'; (void)printf("%s\n", p); exit(0); } |