sbase

suckless unix tools
git clone git://git.2f30.org/sbase.git
Log | Files | Refs | README | LICENSE

commit 6e8b79ebd8186be3e955bb26877f72f45292edf7
parent 09fcbfc338f7401019565ef286d3cc508a59f4e9
Author: sin <sin@2f30.org>
Date:   Wed Oct 16 17:54:29 +0100

Add -s support for du(1)

Diffstat:
du.1 | 3+++
du.c | 22+++++++++++++++++-----
2 files changed, 20 insertions(+), 5 deletions(-)
diff --git a/du.1 b/du.1 @@ -16,3 +16,6 @@ directory is displayed. .TP .BI \-a Display an entry for each file in the file hierarchy. +.TP +.BI \-s +Display only the grand total for the specified files. diff --git a/du.c b/du.c @@ -14,8 +14,10 @@ static long blksize = 512; static bool aflag = false; +static bool sflag = false; static long du(const char *); +static void print(long n, char *path); void usage(void) @@ -27,11 +29,15 @@ int main(int argc, char *argv[]) { char *bsize; + long n; ARGBEGIN { case 'a': aflag = true; break; + case 's': + sflag = true; + break; default: usage(); } ARGEND; @@ -41,10 +47,15 @@ main(int argc, char *argv[]) blksize = estrtol(bsize, 0); if (argc < 1) { - du("."); + n = du("."); + if (sflag) + print(n, realpath(".", NULL)); } else { - for (; argc > 0; argc--, argv++) - du(argv[0]); + for (; argc > 0; argc--, argv++) { + n = du(argv[0]); + if (sflag) + print(n, realpath(argv[0], NULL)); + } } return EXIT_SUCCESS; } @@ -106,7 +117,7 @@ du(const char *path) } else { m = 512 * st.st_blocks / blksize; n += m; - if (aflag) + if (aflag && !sflag) print(m, realpath(dent->d_name, NULL)); } } @@ -115,6 +126,7 @@ du(const char *path) } } - print(n, realpath(path, NULL)); + if (!sflag) + print(n, realpath(path, NULL)); return n; }