summaryrefslogtreecommitdiff
path: root/dirname.c
diff options
context:
space:
mode:
authorEric Andersen2000-12-12 23:27:48 +0000
committerEric Andersen2000-12-12 23:27:48 +0000
commit483262f633837f98c02261fb035dd25845cbe893 (patch)
tree261f7093500d43f6fac2192b1193900949b5f6a1 /dirname.c
parent4d4b3b1d88296efab67e789a676feb61b7929412 (diff)
downloadbusybox-483262f633837f98c02261fb035dd25845cbe893.zip
busybox-483262f633837f98c02261fb035dd25845cbe893.tar.gz
Patch from Matt Kraai to fix 'dirname /'
Diffstat (limited to 'dirname.c')
-rw-r--r--dirname.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/dirname.c b/dirname.c
index ceb750c..63c557a 100644
--- a/dirname.c
+++ b/dirname.c
@@ -32,13 +32,14 @@ extern int dirname_main(int argc, char **argv)
argv++;
s=*argv+strlen(*argv)-1;
- while (s && *s == '/') {
- *s = '\0';
- s=*argv+strlen(*argv)-1;
+ while (s != *argv && *s == '/') {
+ *s-- = '\0';
}
s = strrchr(*argv, '/');
- if (s && *s)
+ if (s != NULL && s == *argv)
+ s[1] = '\0';
+ else if (s != NULL)
*s = '\0';
- printf("%s\n", (s)? *argv : ".");
+ puts(s ? *argv : ".");
return EXIT_SUCCESS;
}