=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/du/du.c,v retrieving revision 1.25 retrieving revision 1.26 diff -c -r1.25 -r1.26 *** src/usr.bin/du/du.c 2014/05/20 01:25:23 1.25 --- src/usr.bin/du/du.c 2014/10/17 14:46:54 1.26 *************** *** 1,4 **** ! /* $OpenBSD: du.c,v 1.25 2014/05/20 01:25:23 guenther Exp $ */ /* $NetBSD: du.c,v 1.11 1996/10/18 07:20:35 thorpej Exp $ */ /* --- 1,4 ---- ! /* $OpenBSD: du.c,v 1.26 2014/10/17 14:46:54 schwarze Exp $ */ /* $NetBSD: du.c,v 1.11 1996/10/18 07:20:35 thorpej Exp $ */ /* *************** *** 40,45 **** --- 40,46 ---- #include #include #include + #include #include #include #include *************** *** 59,74 **** FTSENT *p; long blocksize; quad_t totalblocks; ! int ftsoptions, listdirs, listfiles; ! int Hflag, Lflag, aflag, cflag, hflag, kflag, sflag; int ch, notused, rval; char **save; save = argv; ! Hflag = Lflag = aflag = cflag = hflag = kflag = sflag = 0; totalblocks = 0; ftsoptions = FTS_PHYSICAL; ! while ((ch = getopt(argc, argv, "HLPachksxr")) != -1) switch (ch) { case 'H': Hflag = 1; --- 60,77 ---- FTSENT *p; long blocksize; quad_t totalblocks; ! int ftsoptions, listfiles, maxdepth; ! int Hflag, Lflag, cflag, hflag, kflag; int ch, notused, rval; char **save; + const char *errstr; save = argv; ! Hflag = Lflag = cflag = hflag = kflag = listfiles = 0; totalblocks = 0; ftsoptions = FTS_PHYSICAL; ! maxdepth = -1; ! while ((ch = getopt(argc, argv, "HLPacd:hkrsx")) != -1) switch (ch) { case 'H': Hflag = 1; *************** *** 82,92 **** Hflag = Lflag = 0; break; case 'a': ! aflag = 1; break; case 'c': cflag = 1; break; case 'h': hflag = 1; kflag = 0; --- 85,102 ---- Hflag = Lflag = 0; break; case 'a': ! listfiles = 1; break; case 'c': cflag = 1; break; + case 'd': + maxdepth = strtonum(optarg, 0, INT_MAX, &errstr); + if (errstr) { + warnx("max depth %s: %s", optarg, errstr); + usage(); + } + break; case 'h': hflag = 1; kflag = 0; *************** *** 96,102 **** hflag = 0; break; case 's': ! sflag = 1; break; case 'r': break; --- 106,112 ---- hflag = 0; break; case 's': ! maxdepth = 0; break; case 'r': break; *************** *** 129,144 **** ftsoptions |= FTS_LOGICAL; } ! if (aflag) { ! if (sflag) ! usage(); ! listdirs = listfiles = 1; ! } else if (sflag) ! listdirs = listfiles = 0; ! else { ! listfiles = 0; ! listdirs = 1; ! } if (!*argv) { argv = save; --- 139,146 ---- ftsoptions |= FTS_LOGICAL; } ! if (maxdepth == -1) ! maxdepth = INT_MAX; if (!*argv) { argv = save; *************** *** 171,182 **** * or directories and this is post-order of the * root of a traversal, display the total. */ ! if (listdirs || ! (!listfiles && p->fts_level == FTS_ROOTLEVEL)) { prtout((quad_t)howmany(p->fts_number, (unsigned long)blocksize), p->fts_path, hflag); - } break; case FTS_DC: /* Ignore. */ break; --- 173,182 ---- * or directories and this is post-order of the * root of a traversal, display the total. */ ! if (p->fts_level <= maxdepth) prtout((quad_t)howmany(p->fts_number, (unsigned long)blocksize), p->fts_path, hflag); break; case FTS_DC: /* Ignore. */ break; *************** *** 193,199 **** * If listing each file, or a non-directory file was * the root of a traversal, display the total. */ ! if (listfiles || p->fts_level == FTS_ROOTLEVEL) prtout(howmany(p->fts_statp->st_blocks, blocksize), p->fts_path, hflag); p->fts_parent->fts_number += p->fts_statp->st_blocks; --- 193,199 ---- * If listing each file, or a non-directory file was * the root of a traversal, display the total. */ ! if (listfiles && p->fts_level <= maxdepth) prtout(howmany(p->fts_statp->st_blocks, blocksize), p->fts_path, hflag); p->fts_parent->fts_number += p->fts_statp->st_blocks; *************** *** 315,320 **** { (void)fprintf(stderr, ! "usage: du [-a | -s] [-chkrx] [-H | -L | -P] [file ...]\n"); exit(1); } --- 315,320 ---- { (void)fprintf(stderr, ! "usage: du [-d depth] [-achkrsx] [-H | -L | -P] [file ...]\n"); exit(1); }