From 483262f633837f98c02261fb035dd25845cbe893 Mon Sep 17 00:00:00 2001 From: Eric Andersen Date: Tue, 12 Dec 2000 23:27:48 +0000 Subject: [PATCH] Patch from Matt Kraai to fix 'dirname /' --- coreutils/dirname.c | 11 ++++++----- dirname.c | 11 ++++++----- 2 files changed, 12 insertions(+), 10 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; } diff --git a/dirname.c b/dirname.c index ceb750cb8..63c557a29 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; } -- 2.25.1