diff options
author | rwatson <rwatson@FreeBSD.org> | 2008-03-09 12:46:39 +0000 |
---|---|---|
committer | rwatson <rwatson@FreeBSD.org> | 2008-03-09 12:46:39 +0000 |
commit | af8220297084dd222e3114c4b65b1f6cb2ee6765 (patch) | |
tree | 3cdb1012a3150a7797c354c731fab47ffbd1702b /bin | |
parent | f0bfd374ce10c7d8b8f9cec3106ac11de1c97abc (diff) | |
download | FreeBSD-src-af8220297084dd222e3114c4b65b1f6cb2ee6765.zip FreeBSD-src-af8220297084dd222e3114c4b65b1f6cb2ee6765.tar.gz |
Enhance realpath(1) in a number of ways:
- Allow realpath to accept multiple paths on the command line.
- Add -q to suppress warnings if some paths can't be processed, and use
getopt(3) to process flags.
- Print the path being requested rather than a possibly partially
processed path when a failure occurs so that you can tell which of
several passed paths did fail.
MFC after: 1 week
PR: 112920
Submitted by: Ighighi <ighighi@gmail.com>
Diffstat (limited to 'bin')
-rw-r--r-- | bin/realpath/realpath.1 | 8 | ||||
-rw-r--r-- | bin/realpath/realpath.c | 33 |
2 files changed, 34 insertions, 7 deletions
diff --git a/bin/realpath/realpath.1 b/bin/realpath/realpath.1 index 3b39545..cf904ed 100644 --- a/bin/realpath/realpath.1 +++ b/bin/realpath/realpath.1 @@ -41,7 +41,9 @@ .Nd return resolved physical path .Sh SYNOPSIS .Nm +.Op Fl q .Ar path +.Op Ar ... .Sh DESCRIPTION The .Nm @@ -55,6 +57,12 @@ and .Pa /../ in .Ar path . +.Pp +If +.Fl q +is specified, warnings will not be printed when +.Xr realpath 3 +fails. .Sh EXIT STATUS .Ex -std .Sh SEE ALSO diff --git a/bin/realpath/realpath.c b/bin/realpath/realpath.c index b0a2c9e..99f5a9d5 100644 --- a/bin/realpath/realpath.c +++ b/bin/realpath/realpath.c @@ -44,20 +44,39 @@ main(int argc, char *argv[]) { char buf[PATH_MAX]; char *p; + int ch, i, qflag, rval; - if (argc == 2) { - if ((p = realpath(argv[1], buf)) == NULL) - err(1, "%s", buf); - } else + qflag = 0; + while ((ch = getopt(argc, argv, "q")) != -1) { + switch (ch) { + case 'q': + qflag = 1; + break; + case '?': + default: + usage(); + } + } + argc -= optind; + argv += optind; + if (argc < 1) usage(); - (void)printf("%s\n", p); - exit(0); + rval = 0; + for (i = 0; i < argc; i++) { + if ((p = realpath(argv[i], buf)) == NULL) { + if (!qflag) + warn("%s", argv[i]); + rval = 1; + } else + (void)printf("%s\n", p); + } + exit(rval); } static void usage(void) { - (void)fprintf(stderr, "usage: realpath path\n"); + (void)fprintf(stderr, "usage: realpath [-q] path [...]\n"); exit(1); } |