Mercurial > hg > toybox
comparison 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 |
comparison
equal
deleted
inserted
replaced
1275:6f18a0845db3 | 1276:d48bdc1cb017 |
---|---|
53 char *name = "total"; | 53 char *name = "total"; |
54 | 54 |
55 if (TT.maxdepth && TT.depth > TT.maxdepth) return; | 55 if (TT.maxdepth && TT.depth > TT.maxdepth) return; |
56 | 56 |
57 if (toys.optflags & FLAG_h) { | 57 if (toys.optflags & FLAG_h) { |
58 char buf[32]; | 58 human_readable(toybuf, size); |
59 int index, sz; | 59 printf("%s", toybuf); |
60 | |
61 for (index = 0; 1024 < size>>(10*index); index++); | |
62 sz = size>>(10*index); | |
63 if (sz < 10) { | |
64 sprintf(buf, "%llu", size>>(10*(index-1))); | |
65 printf("%c.%c", buf[0], buf[1]); | |
66 } else printf("%d", sz); | |
67 if (index) printf("%c", " KMGTPE"[index]); | |
68 } else { | 60 } else { |
69 int bits = 10; | 61 int bits = 10; |
70 | 62 |
71 if (toys.optflags & FLAG_K) bits = 9; | 63 if (toys.optflags & FLAG_K) bits = 9; |
72 else if (toys.optflags & FLAG_m) bits = 20; | 64 else if (toys.optflags & FLAG_m) bits = 20; |