diff options
author | tjr <tjr@FreeBSD.org> | 2002-05-18 02:47:25 +0000 |
---|---|---|
committer | tjr <tjr@FreeBSD.org> | 2002-05-18 02:47:25 +0000 |
commit | f0c2951e6ba24b0077b2d99ab4c4cf11a21154da (patch) | |
tree | f4201e9601e52092c580b5b269f3846bf30e2706 | |
parent | feb720dec591489f53df48c52dcc0dbff33c4112 (diff) | |
download | FreeBSD-src-f0c2951e6ba24b0077b2d99ab4c4cf11a21154da.zip FreeBSD-src-f0c2951e6ba24b0077b2d99ab4c4cf11a21154da.tar.gz |
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.
-rw-r--r-- | bin/pwd/pwd.1 | 4 | ||||
-rw-r--r-- | bin/pwd/pwd.c | 23 |
2 files changed, 16 insertions, 11 deletions
diff --git a/bin/pwd/pwd.1 b/bin/pwd/pwd.1 index f2ac73d..7add662 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 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); } |