From 9d2915993141096352322738e5e50b4c0bf42a8d Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Wed, 25 Oct 2000 08:39:29 +0000 Subject: Include dirname.h. (main): Use dir_name_r rather than open-coding it. --- src/dirname.c | 22 ++++++---------------- 1 file 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); } -- cgit v1.2.3-70-g09d2