summaryrefslogtreecommitdiffstats
path: root/usr.bin/du/du.c
diff options
context:
space:
mode:
authorkeramida <keramida@FreeBSD.org>2008-02-25 19:06:43 +0000
committerkeramida <keramida@FreeBSD.org>2008-02-25 19:06:43 +0000
commit67638f8d86ed7b5408ba9ed6f4d3840ae7de3a03 (patch)
treebe80ec6ff9c0843d2cb2004c39dfbfd2c3d204c0 /usr.bin/du/du.c
parentf1033f806d4ac62a8881815fad77e2587b4248fa (diff)
downloadFreeBSD-src-67638f8d86ed7b5408ba9ed6f4d3840ae7de3a03.zip
FreeBSD-src-67638f8d86ed7b5408ba9ed6f4d3840ae7de3a03.tar.gz
Implement from scratch a -l option for du(1), to match the same option
of the GNU utility. The default behavior of our original `du' is to count hardlinked files only once for each invocation of the utility. With the new -l option they count towards the final size every time they are found. PR: bin/117944 Submitted by: keramida Reviewed by: des, obrien MFC after: 2 weeks
Diffstat (limited to 'usr.bin/du/du.c')
-rw-r--r--usr.bin/du/du.c17
1 files changed, 12 insertions, 5 deletions
diff --git a/usr.bin/du/du.c b/usr.bin/du/du.c
index ba369f9..8959293 100644
--- a/usr.bin/du/du.c
+++ b/usr.bin/du/du.c
@@ -90,20 +90,22 @@ main(int argc, char *argv[])
int ftsoptions;
int listall;
int depth;
- int Hflag, Lflag, Pflag, aflag, sflag, dflag, cflag, hflag, ch, notused, rval;
+ int Hflag, Lflag, Pflag, 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 = 0;
+ Hflag = Lflag = Pflag = aflag = sflag = dflag = cflag = hflag =
+ lflag = 0;
save = argv;
ftsoptions = 0;
depth = INT_MAX;
SLIST_INIT(&ignores);
- while ((ch = getopt(argc, argv, "HI:LPasd:chkmnrx")) != -1)
+ while ((ch = getopt(argc, argv, "HI:LPasd:chklmnrx")) != -1)
switch (ch) {
case 'H':
Hflag = 1;
@@ -150,6 +152,9 @@ main(int argc, char *argv[])
if (setenv("BLOCKSIZE", "1024", 1) == -1)
warn("setenv: cannot set BLOCKSIZE=1024");
break;
+ case 'l':
+ lflag = 1;
+ break;
case 'm':
hflag = 0;
if (setenv("BLOCKSIZE", "1048576", 1) == -1)
@@ -261,7 +266,8 @@ main(int argc, char *argv[])
if (ignorep(p))
break;
- if (p->fts_statp->st_nlink > 1 && linkchk(p))
+ if (lflag == 0 &&
+ p->fts_statp->st_nlink > 1 && linkchk(p))
break;
if (listall || p->fts_level == 0) {
@@ -447,7 +453,8 @@ static void
usage(void)
{
(void)fprintf(stderr,
- "usage: du [-H | -L | -P] [-a | -s | -d depth] [-c] [-h | -k | -m] [-n] [-x] [-I mask] [file ...]\n");
+ "usage: du [-H | -L | -P] [-a | -s | -d depth] [-c] "
+ "[-l] [-h | -k | -m] [-n] [-x] [-I mask] [file ...]\n");
exit(EX_USAGE);
}
OpenPOWER on IntegriCloud