[hackers] [sbase] Add -s support for du(1) || sin
commit 6e8b79ebd8186be3e955bb26877f72f45292edf7
Author: sin <sin_AT_2f30.org>
Date: Wed Oct 16 17:54:29 2013 +0100
Add -s support for du(1)
diff --git a/du.1 b/du.1
index a5046e1..932e693 100644
--- a/du.1
+++ b/du.1
_AT_@ -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
index bfb40e6..3c6461b 100644
--- a/du.c
+++ b/du.c
_AT_@ -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)
_AT_@ -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;
_AT_@ -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;
}
_AT_@ -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));
}
}
_AT_@ -115,6 +126,7 @@ du(const char *path)
}
}
- print(n, realpath(path, NULL));
+ if (!sflag)
+ print(n, realpath(path, NULL));
return n;
}
Received on Wed Oct 16 2013 - 20:22:50 CEST
This archive was generated by hypermail 2.3.0
: Wed Oct 16 2013 - 20:24:21 CEST