aboutsummaryrefslogtreecommitdiff
path: root/toys
diff options
context:
space:
mode:
authorTryn Mirell <tryn@mirell.org>2012-01-15 23:27:22 -0600
committerTryn Mirell <tryn@mirell.org>2012-01-15 23:27:22 -0600
commit0bc08c8bfddc8910387368d44e8ae3124e2963f1 (patch)
treef467108e506caea649be3c1696a2891b9bde7c53 /toys
parentde584eb24173d6b708170ee1900fcec47091365e (diff)
downloadtoybox-0bc08c8bfddc8910387368d44e8ae3124e2963f1.tar.gz
'basename': Handle where we have no / passed
Diffstat (limited to 'toys')
-rw-r--r--toys/basename.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/toys/basename.c b/toys/basename.c
index 33307327..db70a5ec 100644
--- a/toys/basename.c
+++ b/toys/basename.c
@@ -26,7 +26,7 @@ void basename_main(void)
if (!arg) return;
arglen = strlen(arg);
-
+
// handle the case where we only have single slash
if (arglen == 1 && arg[0] == '/') {
puts("/");
@@ -39,7 +39,10 @@ void basename_main(void)
}
// get everything past the last /
- base = strrchr(arg, '/') + 1;
+ base = strrchr(arg, '/');
+
+ if (!base) base = arg;
+ else base++;
// handle the case where we have all slashes
if (base[0] == 0) base = "/";