From 90e8605ea587c4ebd00de77e3c71551b6e26b7c0 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Fri, 4 Jan 2013 21:10:49 -0600 Subject: Make basename use basename(). --- toys/posix/basename.c | 17 +++-------------- 1 file 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); -- cgit v1.2.3