du: Don't print 0 entry if stat of named file fails
Previously: $ du doesntexist du: lstat doesntexist: No such file or directory 0 doesntexist Now: $ du doesntexist du: lstat doesntexist: No such file or directory Also, just call nblks one time.
This commit is contained in:
parent
a5612b0d08
commit
830ca05c25
15
du.c
15
du.c
|
@ -35,16 +35,19 @@ nblks(blkcnt_t blocks)
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
du(const char *path, struct stat *st, void *total, struct recursor *r)
|
du(const char *path, struct stat *st, void *data, struct recursor *r)
|
||||||
{
|
{
|
||||||
off_t subtotal = 0;
|
off_t *total = data, subtotal;
|
||||||
|
|
||||||
|
subtotal = nblks(st->st_blocks);
|
||||||
if (S_ISDIR(st->st_mode))
|
if (S_ISDIR(st->st_mode))
|
||||||
recurse(path, &subtotal, r);
|
recurse(path, &subtotal, r);
|
||||||
*((off_t *)total) += subtotal + nblks(st->st_blocks);
|
*total += subtotal;
|
||||||
|
|
||||||
if (!sflag && r->depth <= maxdepth && r->depth && (S_ISDIR(st->st_mode) || aflag))
|
if (!r->depth)
|
||||||
printpath(subtotal + nblks(st->st_blocks), path);
|
printpath(*total, path);
|
||||||
|
else if (!sflag && r->depth <= maxdepth && (S_ISDIR(st->st_mode) || aflag))
|
||||||
|
printpath(subtotal, path);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -102,12 +105,10 @@ main(int argc, char *argv[])
|
||||||
|
|
||||||
if (!argc) {
|
if (!argc) {
|
||||||
recurse(".", &n, &r);
|
recurse(".", &n, &r);
|
||||||
printpath(n, ".");
|
|
||||||
} else {
|
} else {
|
||||||
for (; *argv; argc--, argv++) {
|
for (; *argv; argc--, argv++) {
|
||||||
n = 0;
|
n = 0;
|
||||||
recurse(*argv, &n, &r);
|
recurse(*argv, &n, &r);
|
||||||
printpath(n, *argv);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user