[hackers] [sbase] Always round up to the next blocksize unit in du(1) || sin

From: <git_AT_suckless.org>
Date: Fri, 18 Oct 2013 17:42:22 +0200

commit 0690c1a0038c5e89780643c42c28e708a65f3764
Author: sin <sin_AT_2f30.org>
Date: Fri Oct 18 16:40:31 2013 +0100

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

diff --git a/du.c b/du.c
index 44281fd..e7a64f3 100644
--- a/du.c
+++ b/du.c
_AT_@ -97,6 +97,12 @@ pop(char *path)
 }
 
 static long
+nblks(struct stat *st)
+{
+ return (512 * st->st_blocks + blksize - 1) / blksize;
+}
+
+static long
 du(const char *path)
 {
         DIR *dp;
_AT_@ -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;
_AT_@ -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))
Received on Fri Oct 18 2013 - 17:42:22 CEST

This archive was generated by hypermail 2.3.0 : Fri Oct 18 2013 - 17:48:11 CEST