aboutsummaryrefslogtreecommitdiff
path: root/toys
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2007-11-27 01:06:43 -0600
committerRob Landley <rob@landley.net>2007-11-27 01:06:43 -0600
commit860902c175ba5d4965159b31e942e7f6c0933b50 (patch)
treefed77fed117bf5d64e9fb05dddd18b3f44e702e7 /toys
parentc15b3edf55ebd915b234e2ee6280a19874a052f9 (diff)
downloadtoybox-860902c175ba5d4965159b31e942e7f6c0933b50.tar.gz
Remove a few bytes from basename and add 'em back (and more) in the help string.
Diffstat (limited to 'toys')
-rw-r--r--toys/Config.in4
-rw-r--r--toys/basename.c18
2 files changed, 13 insertions, 9 deletions
diff --git a/toys/Config.in b/toys/Config.in
index 34c31107..e387d245 100644
--- a/toys/Config.in
+++ b/toys/Config.in
@@ -15,9 +15,9 @@ config BASENAME
bool "basename"
default y
help
- usage: basename path
+ usage: basename path [suffix]
- Print the part of path after the last slash.
+ Print the part of path after the last slash, optionally minus suffix.
config BZCAT
bool "bzcat"
diff --git a/toys/basename.c b/toys/basename.c
index 2ea6882c..da843b86 100644
--- a/toys/basename.c
+++ b/toys/basename.c
@@ -1,14 +1,18 @@
+/* vi: set sw=4 ts=4: */
+/* basename.c - print non-directory portion of path
+ *
+ * See http://www.opengroup.org/onlinepubs/009695399/utilities/basename.html
+ */
+
#include "toys.h"
int basename_main(void)
{
- char *name = basename(toys.optargs[0]);
- if (toys.optargs[1]) {
- int slen = strlen(toys.optargs[1]);
- int name_len = strlen(name);
- if (slen < name_len)
- if (!strcmp(name+name_len-slen, toys.optargs[1]))
- *(name+name_len-slen) = '\0';
+ char *name = basename(*toys.optargs);
+ char *suffix = toys.optargs[1];
+ if (suffix) {
+ char *end = name+strlen(name)-strlen(suffix);
+ if (end>name && !strcmp(end,suffix)) *end=0;
}
puts(name);
return 0;