Mercurial > hg > toybox
changeset 781:b300eb824c70
Make basename use basename().
author | Rob Landley <rob@landley.net> |
---|---|
date | Fri, 04 Jan 2013 21:10:49 -0600 |
parents | 6cc69be43c42 |
children | 3d7526f6115b |
files | toys/posix/basename.c |
diffstat | 1 files changed, 3 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
--- a/toys/posix/basename.c Wed Jan 02 02:00:35 2013 -0600 +++ b/toys/posix/basename.c Fri Jan 04 21:10:49 2013 -0600 @@ -20,23 +20,12 @@ 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);