| Summary: | basename(1) ignores suffix argument | ||
|---|---|---|---|
| Product: | Base System | Reporter: | Atsushi Onoe <onoe> |
| Component: | bin | Assignee: | Dag-Erling Smørgrav <des> |
| Status: | Closed FIXED | ||
| Severity: | Affects Only Me | ||
| Priority: | Normal | ||
| Version: | 5.0-CURRENT | ||
| Hardware: | Any | ||
| OS: | Any | ||
|
Description
Atsushi Onoe
2000-09-05 15:10:01 UTC
> From: Atsushi Onoe <onoe@duplo.sm.sony.co.jp> Sorry, I've mailed with wrong address. Atsushi Onoe <onoe@sm.sony.co.jp> Responsible Changed From-To: freebsd-bugs->des Over to DES, so that he can review the patch I'm about to send. On Tue, 05 Sep 2000 23:02:41 +0900, Atsushi Onoe wrote:
> >Number: 21061
> >Category: bin
> >Synopsis: basename(1) ignores suffix argument
Try this. The code that DES replaced has not been reinstated verbatim
because of style bugs.
Ciao,
Sheldon.
Index: basename.c
===================================================================
RCS file: /home/ncvs/src/usr.bin/basename/basename.c,v
retrieving revision 1.4
diff -u -d -r1.4 basename.c
--- basename.c 2000/09/03 17:09:41 1.4
+++ basename.c 2000/09/05 14:26:00
@@ -43,6 +43,7 @@
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 <unistd.h>
@@ -54,7 +55,8 @@
int argc;
char **argv;
{
- int ch;
+ int ch, stringlen, off, suffixlen;
+ char *p;
while ((ch = getopt(argc, argv, "")) != -1)
switch(ch) {
@@ -68,7 +70,19 @@
if (argc != 1 && argc != 2)
usage();
- (void)printf("%s\n", basename(*argv));
+ if ((p = basename(*argv)) == NULL)
+ err(1, "%s", *argv);
+ if (*++argv) {
+ stringlen = strlen(p);
+ suffixlen = strlen(*argv);
+
+ if (suffixlen < stringlen) {
+ off = stringlen - suffixlen;
+ if (!strcmp(p + off, *argv))
+ p[off] = '\0';
+ }
+ }
+ (void)printf("%s\n", p);
exit(0);
}
State Changed From-To: open->closed Fixed today: 1.5 +9 -2 src/usr.bin/basename/basename.c 1.7 +6 -2 src/usr.bin/dirname/dirname.c |