=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/du/du.c,v retrieving revision 1.2 retrieving revision 1.3 diff -c -r1.2 -r1.3 *** src/usr.bin/du/du.c 1996/06/26 05:32:38 1.2 --- src/usr.bin/du/du.c 1996/10/18 18:16:07 1.3 *************** *** 1,5 **** ! /* $OpenBSD: du.c,v 1.2 1996/06/26 05:32:38 deraadt Exp $ */ ! /* $NetBSD: du.c,v 1.10 1995/09/28 06:19:56 perry Exp $ */ /* * Copyright (c) 1989, 1993, 1994 --- 1,5 ---- ! /* $OpenBSD: du.c,v 1.3 1996/10/18 18:16:07 millert Exp $ */ ! /* $NetBSD: du.c,v 1.11 1996/10/18 07:20:35 thorpej Exp $ */ /* * Copyright (c) 1989, 1993, 1994 *************** *** 47,53 **** #if 0 static char sccsid[] = "@(#)du.c 8.5 (Berkeley) 5/4/95"; #else ! static char rcsid[] = "$OpenBSD: du.c,v 1.2 1996/06/26 05:32:38 deraadt Exp $"; #endif #endif /* not lint */ --- 47,53 ---- #if 0 static char sccsid[] = "@(#)du.c 8.5 (Berkeley) 5/4/95"; #else ! static char rcsid[] = "$OpenBSD: du.c,v 1.3 1996/10/18 18:16:07 millert Exp $"; #endif #endif /* not lint */ *************** *** 73,87 **** { FTS *fts; FTSENT *p; ! long blocksize; int ftsoptions, listdirs, listfiles; ! int Hflag, Lflag, Pflag, aflag, ch, kflag, notused, rval, sflag; char **save; save = argv; ! Hflag = Lflag = Pflag = aflag = kflag = sflag = 0; ftsoptions = FTS_PHYSICAL; ! while ((ch = getopt(argc, argv, "HLPaksx")) != EOF) switch (ch) { case 'H': Hflag = 1; --- 73,88 ---- { FTS *fts; FTSENT *p; ! long blocksize, totalblocks; int ftsoptions, listdirs, listfiles; ! int Hflag, Lflag, Pflag, aflag, ch, cflag, kflag, notused, rval, sflag; char **save; save = argv; ! Hflag = Lflag = Pflag = aflag = cflag = kflag = sflag = 0; ! totalblocks = 0; ftsoptions = FTS_PHYSICAL; ! while ((ch = getopt(argc, argv, "HLPacksx")) != EOF) switch (ch) { case 'H': Hflag = 1; *************** *** 98,103 **** --- 99,107 ---- case 'a': aflag = 1; break; + case 'c': + cflag = 1; + break; case 'k': blocksize = 1024; kflag = 1; *************** *** 156,162 **** blocksize /= 512; if ((fts = fts_open(argv, ftsoptions, NULL)) == NULL) ! err(1, NULL); for (rval = 0; (p = fts_read(fts)) != NULL;) switch (p->fts_info) { --- 160,166 ---- blocksize /= 512; if ((fts = fts_open(argv, ftsoptions, NULL)) == NULL) ! err(1, "fts_open"); for (rval = 0; (p = fts_read(fts)) != NULL;) switch (p->fts_info) { *************** *** 165,176 **** case FTS_DP: p->fts_parent->fts_number += p->fts_number += p->fts_statp->st_blocks; /* * If listing each directory, or not listing files * or directories and this is post-order of the * root of a traversal, display the total. */ ! if (listdirs || !listfiles && !p->fts_level) (void)printf("%ld\t%s\n", howmany(p->fts_number, blocksize), p->fts_path); --- 169,182 ---- case FTS_DP: p->fts_parent->fts_number += p->fts_number += p->fts_statp->st_blocks; + if (cflag) + totalblocks += p->fts_statp->st_blocks; /* * If listing each directory, or not listing files * or directories and this is post-order of the * root of a traversal, display the total. */ ! if (listdirs || (!listfiles && !p->fts_level)) (void)printf("%ld\t%s\n", howmany(p->fts_number, blocksize), p->fts_path); *************** *** 195,203 **** --- 201,214 ---- howmany(p->fts_statp->st_blocks, blocksize), p->fts_path); p->fts_parent->fts_number += p->fts_statp->st_blocks; + if (cflag) + totalblocks += p->fts_statp->st_blocks; } if (errno) err(1, "fts_read"); + if (cflag) + (void)printf("%ld\ttotal\n", + howmany(totalblocks, blocksize)); exit(0); } *************** *** 225,231 **** if (nfiles == maxfiles && (files = realloc((char *)files, (u_int)(sizeof(ID) * (maxfiles += 128)))) == NULL) ! err(1, ""); files[nfiles].inode = ino; files[nfiles].dev = dev; ++nfiles; --- 236,242 ---- if (nfiles == maxfiles && (files = realloc((char *)files, (u_int)(sizeof(ID) * (maxfiles += 128)))) == NULL) ! err(1, "can't allocate memory"); files[nfiles].inode = ino; files[nfiles].dev = dev; ++nfiles; *************** *** 237,242 **** { (void)fprintf(stderr, ! "usage: du [-H | -L | -P] [-a | -s] [-kx] [file ...]\n"); exit(1); } --- 248,253 ---- { (void)fprintf(stderr, ! "usage: du [-H | -L | -P] [-a | -s] [-ckx] [file ...]\n"); exit(1); }