summaryrefslogtreecommitdiffstats
path: root/bin/pwd/pwd.c
diff options
context:
space:
mode:
authorphk <phk@FreeBSD.org>2000-11-24 10:18:52 +0000
committerphk <phk@FreeBSD.org>2000-11-24 10:18:52 +0000
commitaedcd50082f71cd5cc88eebd3fb44c4ce6bd4a23 (patch)
tree8740cb837c511ab4e712d3eafa35fde5de44ad53 /bin/pwd/pwd.c
parent8086c436850659d90d076656d620daeccff4054d (diff)
downloadFreeBSD-src-aedcd50082f71cd5cc88eebd3fb44c4ce6bd4a23.zip
FreeBSD-src-aedcd50082f71cd5cc88eebd3fb44c4ce6bd4a23.tar.gz
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.
Diffstat (limited to 'bin/pwd/pwd.c')
-rw-r--r--bin/pwd/pwd.c21
1 files changed, 15 insertions, 6 deletions
diff --git a/bin/pwd/pwd.c b/bin/pwd/pwd.c
index 1adb3c8..849c309 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);
}
OpenPOWER on IntegriCloud