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>
This commit is contained in:
parent
1b21ffa615
commit
08995e292e
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=176977
@ -41,7 +41,9 @@
|
|||||||
.Nd return resolved physical path
|
.Nd return resolved physical path
|
||||||
.Sh SYNOPSIS
|
.Sh SYNOPSIS
|
||||||
.Nm
|
.Nm
|
||||||
|
.Op Fl q
|
||||||
.Ar path
|
.Ar path
|
||||||
|
.Op Ar ...
|
||||||
.Sh DESCRIPTION
|
.Sh DESCRIPTION
|
||||||
The
|
The
|
||||||
.Nm
|
.Nm
|
||||||
@ -55,6 +57,12 @@ and
|
|||||||
.Pa /../
|
.Pa /../
|
||||||
in
|
in
|
||||||
.Ar path .
|
.Ar path .
|
||||||
|
.Pp
|
||||||
|
If
|
||||||
|
.Fl q
|
||||||
|
is specified, warnings will not be printed when
|
||||||
|
.Xr realpath 3
|
||||||
|
fails.
|
||||||
.Sh EXIT STATUS
|
.Sh EXIT STATUS
|
||||||
.Ex -std
|
.Ex -std
|
||||||
.Sh SEE ALSO
|
.Sh SEE ALSO
|
||||||
|
@ -44,20 +44,39 @@ main(int argc, char *argv[])
|
|||||||
{
|
{
|
||||||
char buf[PATH_MAX];
|
char buf[PATH_MAX];
|
||||||
char *p;
|
char *p;
|
||||||
|
int ch, i, qflag, rval;
|
||||||
|
|
||||||
if (argc == 2) {
|
qflag = 0;
|
||||||
if ((p = realpath(argv[1], buf)) == NULL)
|
while ((ch = getopt(argc, argv, "q")) != -1) {
|
||||||
err(1, "%s", buf);
|
switch (ch) {
|
||||||
} else
|
case 'q':
|
||||||
|
qflag = 1;
|
||||||
|
break;
|
||||||
|
case '?':
|
||||||
|
default:
|
||||||
|
usage();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
argc -= optind;
|
||||||
|
argv += optind;
|
||||||
|
if (argc < 1)
|
||||||
usage();
|
usage();
|
||||||
(void)printf("%s\n", p);
|
rval = 0;
|
||||||
exit(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
|
static void
|
||||||
usage(void)
|
usage(void)
|
||||||
{
|
{
|
||||||
|
|
||||||
(void)fprintf(stderr, "usage: realpath path\n");
|
(void)fprintf(stderr, "usage: realpath [-q] path [...]\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user