summaryrefslogtreecommitdiffstats
path: root/bin/pwd/pwd.c
diff options
context:
space:
mode:
Diffstat (limited to 'bin/pwd/pwd.c')
-rw-r--r--bin/pwd/pwd.c23
1 files changed, 14 insertions, 9 deletions
diff --git a/bin/pwd/pwd.c b/bin/pwd/pwd.c
index db5f2f3..76524c7 100644
--- a/bin/pwd/pwd.c
+++ b/bin/pwd/pwd.c
@@ -61,18 +61,18 @@ void usage(void);
int
main(int argc, char *argv[])
{
- int Lflag, Pflag;
+ int physical;
int ch;
char *p;
- Lflag = Pflag = 0;
+ physical = 0;
while ((ch = getopt(argc, argv, "LP")) != -1)
switch (ch) {
case 'L':
- Lflag = 1;
+ physical = 0;
break;
case 'P':
- Pflag = 1;
+ physical = 1;
break;
case '?':
default:
@@ -81,13 +81,18 @@ main(int argc, char *argv[])
argc -= optind;
argv += optind;
- if (argc != 0 || (Lflag && Pflag))
+ if (argc != 0)
usage();
- p = Lflag ? getcwd_logical() : getcwd(NULL, 0);
- if (p == NULL)
+ /*
+ * If we're trying to find the logical current directory and that
+ * fails, behave as if -P was specified.
+ */
+ if ((!physical && (p = getcwd_logical()) != NULL) ||
+ (p = getcwd(NULL, 0)) != NULL)
+ printf("%s\n", p);
+ else
err(1, ".");
- (void)printf("%s\n", p);
exit(0);
}
@@ -96,7 +101,7 @@ void
usage(void)
{
- (void)fprintf(stderr, "usage: pwd [-L | -P]\n");
+ (void)fprintf(stderr, "usage: pwd [-LP]\n");
exit(1);
}
OpenPOWER on IntegriCloud