diff options
author | Poul-Henning Kamp <phk@FreeBSD.org> | 2000-11-24 10:18:52 +0000 |
---|---|---|
committer | Poul-Henning Kamp <phk@FreeBSD.org> | 2000-11-24 10:18:52 +0000 |
commit | 1082b6873682a1ccab5ab3e76612fea56ca50023 (patch) | |
tree | f54ee2329e97effeed6b24dc0998b9cdac21792b /bin/pwd/pwd.c | |
parent | 92ee29d2a59b9864be5b69f5ec9d249421f9b0ef (diff) | |
download | src-1082b6873682a1ccab5ab3e76612fea56ca50023.tar.gz src-1082b6873682a1ccab5ab3e76612fea56ca50023.zip |
Let the pwd program double as realpath(1).
This lets you resolve pathnames to their underlying physical path:
critter# realpath /sys/kern/subr_disk.c
/freebsd/src/sys/kern/subr_disk.c
Update the pwd man-page slightly.
Notes
Notes:
svn path=/head/; revision=69110
Diffstat (limited to 'bin/pwd/pwd.c')
-rw-r--r-- | bin/pwd/pwd.c | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/bin/pwd/pwd.c b/bin/pwd/pwd.c index 1adb3c86f508..849c309926ac 100644 --- a/bin/pwd/pwd.c +++ b/bin/pwd/pwd.c @@ -49,6 +49,7 @@ static const char rcsid[] = #include <stdio.h> #include <stdlib.h> #include <unistd.h> +#include <sys/param.h> void usage __P((void)); @@ -59,13 +60,13 @@ main(argc, argv) { int ch; char *p; + char buf[MAXPATHLEN]; /* * Flags for pwd are a bit strange. The POSIX 1003.2B/D9 document * has an optional -P flag for physical, which is what this program * will produce by default. The logical flag, -L, should fail, as - * there's no way to display a logical path after forking. We don't - * document either flag, only adding -P for future portability. + * there's no way to display a logical path after forking. */ while ((ch = getopt(argc, argv, "P")) != -1) switch (ch) { @@ -78,12 +79,20 @@ main(argc, argv) argc -= optind; argv += optind; - if (argc != 0) + if (argc == 1) { + p = realpath(argv[0], buf); + if (p == NULL) + err(1, argv[0]); + (void)printf("%s\n", p); + } else if (argc == 0) { + p = getcwd(NULL, 0); + if (p == NULL) + err(1, "."); + (void)printf("%s\n", p); + } else { usage(); + } - if ((p = getcwd(NULL, 0)) == NULL) - err(1, "."); - (void)printf("%s\n", p); exit(0); } |