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.
This commit is contained in:
Tim J. Robbins 2002-05-18 02:47:25 +00:00
parent 6395b411cb
commit 6873c4b7aa
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=96831
2 changed files with 16 additions and 11 deletions

View File

@ -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

View File

@ -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);
}