summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>2000-10-25 08:39:29 +0000
committerJim Meyering <jim@meyering.net>2000-10-25 08:39:29 +0000
commit9d2915993141096352322738e5e50b4c0bf42a8d (patch)
tree85825707f2b97ba33a3e6decd1980989b6c9a852
parent342d5997cc17e6cb986c51a078a7a9cf6f5343ea (diff)
downloadcoreutils-9d2915993141096352322738e5e50b4c0bf42a8d.tar.xz
Include dirname.h.
(main): Use dir_name_r rather than open-coding it.
-rw-r--r--src/dirname.c22
1 files changed, 6 insertions, 16 deletions
diff --git a/src/dirname.c b/src/dirname.c
index cfe7052d1..be1fc4559 100644
--- a/src/dirname.c
+++ b/src/dirname.c
@@ -24,6 +24,7 @@
#include "system.h"
#include "long-options.h"
#include "error.h"
+#include "dirname.h"
#include "closeout.h"
/* The official name of this program (e.g., no `g' prefix). */
@@ -64,8 +65,8 @@ output `.' (meaning the current directory).\n\
int
main (int argc, char **argv)
{
- register char *path;
- register char *slash;
+ const char *result;
+ size_t len;
program_name = argv[0];
setlocale (LC_ALL, "");
@@ -91,20 +92,9 @@ main (int argc, char **argv)
usage (1);
}
- path = argv[1];
- strip_trailing_slashes (path);
-
- slash = strrchr (path, '/');
- if (slash == NULL)
- path = (char *) ".";
- else
- {
- /* Remove any trailing slashes and final element. */
- while (slash > path && *slash == '/')
- --slash;
- slash[1] = 0;
- }
- puts (path);
+ len = dir_name_r (argv[1], &result);
+ fwrite (result, 1, len, stdout);
+ putchar ('\n');
exit (0);
}