diff toys/posix/du.c @ 1276:d48bdc1cb017 draft

Switch human_readable() to just outputing decimal kilo/mega/gigabytes, make du use it, move it from lib/pending.c to lib.c.
author Rob Landley <rob@landley.net>
date Tue, 06 May 2014 06:31:28 -0500
parents 9e105bab92e5
children ffc7f606ce5b
line wrap: on
line diff
--- a/toys/posix/du.c	Tue May 06 06:14:20 2014 -0500
+++ b/toys/posix/du.c	Tue May 06 06:31:28 2014 -0500
@@ -55,16 +55,8 @@
   if (TT.maxdepth && TT.depth > TT.maxdepth) return;
 
   if (toys.optflags & FLAG_h) {
-    char buf[32];
-    int index, sz;
-
-    for (index = 0; 1024 < size>>(10*index); index++);
-    sz = size>>(10*index);
-    if (sz < 10) {
-      sprintf(buf, "%llu", size>>(10*(index-1)));
-      printf("%c.%c", buf[0], buf[1]);
-    } else printf("%d", sz);
-    if (index) printf("%c", " KMGTPE"[index]);
+    human_readable(toybuf, size);
+    printf("%s", toybuf);
   } else {
     int bits = 10;