From: Jim Meyering Date: Thu, 28 Nov 1996 23:50:13 +0000 (+0000) Subject: (find_mount_point): Use strip_trailing_slashes and dirname X-Git-Tag: TEXTUTILS-1_19q~64 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=be44044a29d61b2b06eb1d67d1ec0ea32cd3c70d;p=thirdparty%2Fcoreutils.git (find_mount_point): Use strip_trailing_slashes and dirname instead of open-coding them. When given FILE containing no slashes, chdir to the directory containing it (the current directory) rather than to `..'. --- diff --git a/src/df.c b/src/df.c index ea996a5c06..fa85c2b614 100644 --- a/src/df.c +++ b/src/df.c @@ -30,6 +30,8 @@ #include "save-cwd.h" #include "error.h" +char *dirname (); +void strip_trailing_slashes (); char *xmalloc (); char *xstrdup (); char *xgetcwd (); @@ -310,7 +312,7 @@ show_dev (const char *disk, const char *mount_point, const char *fstype) disk = "-"; /* unknown */ printf ((print_type ? "%-13s" : "%-20s"), disk); - if (strlen (disk) > (print_type ? 13 : 20) && !posix_format) + if ((int) strlen (disk) > (print_type ? 13 : 20) && !posix_format) printf ((print_type ? "\n%13s" : "\n%20s"), ""); if (! fstype) @@ -396,22 +398,13 @@ find_mount_point (file, file_stat) /* FILE is some other kind of file, we need to use its directory. */ { int rv; - char *dir = xstrdup (file); - char *end = dir + strlen (dir); - - /* Strip off the last pathname element of FILE to get the directory. */ - while (end > dir + 1 && end[-1] == '/') - *--end = '\0'; - while (end > dir && end[-1] != '/') - end--; - if (end == dir) - /* FILE only has a single element, use the cwd's parent. */ - rv = chdir (".."); - else - { - *end = '\0'; - rv = chdir (dir); - } + char *tmp = xstrdup (file); + char *dir; + + strip_trailing_slashes (tmp); + dir = dirname (tmp); + free (tmp); + rv = chdir (dir); free (dir); if (rv < 0)