aboutsummaryrefslogtreecommitdiff
path: root/usr.bin/du/du.c
diff options
context:
space:
mode:
authorMarc G. Fournier <scrappy@FreeBSD.org>1996-10-23 06:53:57 +0000
committerMarc G. Fournier <scrappy@FreeBSD.org>1996-10-23 06:53:57 +0000
commit0282769e2d3e0626e3ca3510ea90fbfe8fb37965 (patch)
tree4eb11960a2f9281fc6f32b10e3fe0781bf514a55 /usr.bin/du/du.c
parent845c4ec464ff64b38808cdd1b215b562de7efd7e (diff)
downloadsrc-0282769e2d3e0626e3ca3510ea90fbfe8fb37965.tar.gz
src-0282769e2d3e0626e3ca3510ea90fbfe8fb37965.zip
Add a 'depth (-d#)' flag to du
patched (context diff), compiled (w/ -Wall) and tested Submitted by: John-Mark Gurney <jmg@nike.efn.org>
Notes
Notes: svn path=/head/; revision=19120
Diffstat (limited to 'usr.bin/du/du.c')
-rw-r--r--usr.bin/du/du.c33
1 files changed, 24 insertions, 9 deletions
diff --git a/usr.bin/du/du.c b/usr.bin/du/du.c
index 26747c8af6d5..47f797fef129 100644
--- a/usr.bin/du/du.c
+++ b/usr.bin/du/du.c
@@ -66,14 +66,15 @@ main(argc, argv)
FTS *fts;
FTSENT *p;
long blocksize;
- int ftsoptions, listdirs, listfiles;
- int Hflag, Lflag, Pflag, aflag, ch, notused, rval, sflag;
+ int ftsoptions, listdirs, listfiles, depth;
+ int Hflag, Lflag, Pflag, aflag, ch, notused, rval, sflag, dflag;
char **save;
save = argv;
- Hflag = Lflag = Pflag = aflag = sflag = 0;
+ Hflag = Lflag = Pflag = aflag = sflag = dflag = 0;
+ depth = INT_MAX;
ftsoptions = FTS_PHYSICAL;
- while ((ch = getopt(argc, argv, "HLPaksx")) != EOF)
+ while ((ch = getopt(argc, argv, "HLPad:ksx")) != EOF)
switch (ch) {
case 'H':
Hflag = 1;
@@ -99,6 +100,14 @@ main(argc, argv)
case 'x':
ftsoptions |= FTS_XDEV;
break;
+ case 'd':
+ dflag = 1;
+ depth=atoi(optarg);
+ if(errno == ERANGE) {
+ (void)fprintf(stderr, "Invalid argument to option d: %s", optarg);
+ usage();
+ }
+ break;
case '?':
default:
usage();
@@ -126,12 +135,17 @@ main(argc, argv)
}
if (aflag) {
- if (sflag)
+ if (sflag || dflag)
usage();
listdirs = listfiles = 1;
- } else if (sflag)
+ } else if (sflag) {
+ if (dflag)
+ usage();
listdirs = listfiles = 0;
- else {
+ } else if (dflag) {
+ listfiles = 0;
+ listdirs = 1;
+ } else {
listfiles = 0;
listdirs = 1;
}
@@ -160,7 +174,8 @@ main(argc, argv)
* or directories and this is post-order of the
* root of a traversal, display the total.
*/
- if (listdirs || !listfiles && !p->fts_level)
+ if ((p->fts_level <= depth && listdirs) ||
+ (!listfiles && !p->fts_level))
(void)printf("%ld\t%s\n",
howmany(p->fts_number, blocksize),
p->fts_path);
@@ -227,6 +242,6 @@ usage()
{
(void)fprintf(stderr,
- "usage: du [-H | -L | -P] [-a | -s] [-k] [-x] [file ...]\n");
+ "usage: du [-H | -L | -P] [-a | -s | -d depth] [-k] [-x] [file ...]\n");
exit(1);
}