aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2013-01-04 21:10:49 -0600
committerRob Landley <rob@landley.net>2013-01-04 21:10:49 -0600
commit90e8605ea587c4ebd00de77e3c71551b6e26b7c0 (patch)
treeda824e693a9bd67c13a26456f090318e45743f30
parent662a267c9b52f256b027d0f176a846b1d973ab99 (diff)
downloadtoybox-90e8605ea587c4ebd00de77e3c71551b6e26b7c0.tar.gz
Make basename use basename().
-rw-r--r--toys/posix/basename.c17
1 files changed, 3 insertions, 14 deletions
diff --git a/toys/posix/basename.c b/toys/posix/basename.c
index 75f3baa4..c49a5f36 100644
--- a/toys/posix/basename.c
+++ b/toys/posix/basename.c
@@ -20,23 +20,12 @@ config BASENAME
void basename_main(void)
{
- char *arg = toys.optargs[0], *suffix = toys.optargs[1], *base;
-
- while ((base = strrchr(arg, '/'))) {
- if (base == arg) break;
- if (!base[1]) *base = 0;
- else {
- base++;
- break;
- }
- }
-
- if (!base) base = arg;
+ char *base = basename(*toys.optargs), *suffix = toys.optargs[1];
// chop off the suffix if provided
if (suffix) {
- arg = base + strlen(base) - strlen(suffix);
- if (arg > base && !strcmp(arg, suffix)) *arg = 0;
+ char *s = base + strlen(base) - strlen(suffix);
+ if (s > base && !strcmp(s, suffix)) *s = 0;
}
puts(base);