du: Allow multiple -HLP options, the last one wins.

This matches 4.4BSD tradition and other utilities with these options and is
required by POSIX (POSIX does not specify -P, only -HL).

MFC after:	2 weeks
This commit is contained in:
Jilles Tjoelker 2011-12-17 23:18:14 +00:00
parent d88ccef562
commit 6530d2f2d5
2 changed files with 17 additions and 20 deletions

View File

@ -28,7 +28,7 @@
.\" @(#)du.1 8.2 (Berkeley) 4/1/94
.\" $FreeBSD$
.\"
.Dd December 8, 2011
.Dd December 17, 2011
.Dt DU 1
.Os
.Sh NAME
@ -155,6 +155,13 @@ or
.Fl L
option is specified, storage used by any symbolic links which are
followed is not counted (or displayed).
The
.Fl H ,
.Fl L
and
.Fl P
options override each other and the command's actions are determined
by the last one specified.
.Pp
The
.Fl h, k

View File

@ -89,18 +89,18 @@ main(int argc, char *argv[])
off_t threshold, threshold_sign;
int ftsoptions;
int depth;
int Hflag, Lflag, Pflag, aflag, sflag, dflag, cflag;
int Hflag, Lflag, aflag, sflag, dflag, cflag;
int hflag, lflag, ch, notused, rval;
char **save;
static char dot[] = ".";
setlocale(LC_ALL, "");
Hflag = Lflag = Pflag = aflag = sflag = dflag = cflag = hflag =
Hflag = Lflag = aflag = sflag = dflag = cflag = hflag =
lflag = Aflag = 0;
save = argv;
ftsoptions = 0;
ftsoptions = FTS_PHYSICAL;
savednumber = 0;
threshold = 0;
threshold_sign = 1;
@ -125,19 +125,17 @@ main(int argc, char *argv[])
break;
case 'H':
Hflag = 1;
Lflag = 0;
break;
case 'I':
ignoreadd(optarg);
break;
case 'L':
if (Pflag)
usage();
Lflag = 1;
Hflag = 0;
break;
case 'P':
if (Lflag)
usage();
Pflag = 1;
Hflag = Lflag = 0;
break;
case 'a':
aflag = 1;
@ -210,20 +208,12 @@ main(int argc, char *argv[])
* the man page, so it's a feature.
*/
if (Hflag + Lflag + Pflag > 1)
usage();
if (Hflag + Lflag + Pflag == 0)
Pflag = 1; /* -P (physical) is default */
if (Hflag)
ftsoptions |= FTS_COMFOLLOW;
if (Lflag)
if (Lflag) {
ftsoptions &= ~FTS_PHYSICAL;
ftsoptions |= FTS_LOGICAL;
if (Pflag)
ftsoptions |= FTS_PHYSICAL;
}
if (!Aflag && (cblocksize % DEV_BSIZE) != 0)
cblocksize = howmany(cblocksize, DEV_BSIZE) * DEV_BSIZE;