aboutsummaryrefslogtreecommitdiff
path: root/toys
diff options
context:
space:
mode:
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 = "/";