aboutsummaryrefslogtreecommitdiff
path: root/coreutils
diff options
context:
space:
mode:
Diffstat (limited to 'coreutils')
-rw-r--r--coreutils/dirname.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/coreutils/dirname.c b/coreutils/dirname.c
index ceb750cb8..63c557a29 100644
--- a/coreutils/dirname.c
+++ b/coreutils/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;
}