summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>1996-11-28 23:50:13 +0000
committerJim Meyering <jim@meyering.net>1996-11-28 23:50:13 +0000
commitbe44044a29d61b2b06eb1d67d1ec0ea32cd3c70d (patch)
treeddf7a472e1252067ba47a08cb0d1116b8f8eb8d7 /src
parentae9d9051349b394658d2d2495e00d107d1f44388 (diff)
downloadcoreutils-be44044a29d61b2b06eb1d67d1ec0ea32cd3c70d.tar.xz
(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 `..'.
Diffstat (limited to 'src')
-rw-r--r--src/df.c27
1 files changed, 10 insertions, 17 deletions
diff --git a/src/df.c b/src/df.c
index ea996a5c0..fa85c2b61 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)