Always round up to the next blocksize unit in du(1)

This commit is contained in:
sin 2013-10-18 16:40:31 +01:00
parent 6a680269bf
commit 0690c1a003
1 changed files with 8 additions and 2 deletions

10
du.c
View File

@ -96,6 +96,12 @@ pop(char *path)
free(path);
}
static long
nblks(struct stat *st)
{
return (512 * st->st_blocks + blksize - 1) / blksize;
}
static long
du(const char *path)
{
@ -107,7 +113,7 @@ du(const char *path)
if (lstat(path, &st) < 0)
eprintf("stat: %s:", path);
n = 512 * st.st_blocks / blksize;
n = nblks(&st);
if (!S_ISDIR(st.st_mode))
goto done;
@ -130,7 +136,7 @@ du(const char *path)
n += du(dent->d_name);
continue;
}
m = 512 * st.st_blocks / blksize;
m = nblks(&st);
n += m;
if (aflag && !sflag) {
if (S_ISLNK(st.st_mode))