aboutsummaryrefslogtreecommitdiff
path: root/bin/pwd
diff options
context:
space:
mode:
authorTim J. Robbins <tjr@FreeBSD.org>2002-05-18 02:47:25 +0000
committerTim J. Robbins <tjr@FreeBSD.org>2002-05-18 02:47:25 +0000
commit6873c4b7aa7f5c88acb5f9f56fbc6d43ab316e8c (patch)
treef4201e9601e52092c580b5b269f3846bf30e2706 /bin/pwd
parent6395b411cb2dc6ac85d61e72d7648ea339ad1f22 (diff)
downloadsrc-6873c4b7aa7f5c88acb5f9f56fbc6d43ab316e8c.tar.gz
src-6873c4b7aa7f5c88acb5f9f56fbc6d43ab316e8c.zip
Make -L the default, allow both -L and -P to be specified (last one used
matters), fall back to -P mode if we can't get the logical directory.
Notes
Notes: svn path=/head/; revision=96831
Diffstat (limited to 'bin/pwd')
-rw-r--r--bin/pwd/pwd.14
-rw-r--r--bin/pwd/pwd.c23
2 files changed, 16 insertions, 11 deletions
diff --git a/bin/pwd/pwd.1 b/bin/pwd/pwd.1
index f2ac73d50bbe..7add6625fb1a 100644
--- a/bin/pwd/pwd.1
+++ b/bin/pwd/pwd.1
@@ -43,7 +43,7 @@
.Nd return working directory name
.Sh SYNOPSIS
.Nm
-.Op Fl L | P
+.Op Fl LP
.Sh DESCRIPTION
The
.Nm
@@ -66,7 +66,7 @@ Display the physical current working directory (all symbolic links resolved).
.El
.Pp
If no options are specified, the
-.Fl P
+.Fl L
option is assumed.
.Sh ENVIRONMENT
Environment variables used by
diff --git a/bin/pwd/pwd.c b/bin/pwd/pwd.c
index db5f2f369984..76524c70161b 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);
}