diff options
author | Rob Landley <rob@landley.net> | 2015-09-06 20:10:04 -0500 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2015-09-06 20:10:04 -0500 |
commit | 960100aa9cb588a73125d43ec0b0a7152a95b43f (patch) | |
tree | 8a33efdad74bc2ecf36efaed1b3089101a9a6102 /lib/lib.c | |
parent | 60d1aea2df9a8cc1e975ed5fee079982612f5966 (diff) | |
download | toybox-960100aa9cb588a73125d43ec0b0a7152a95b43f.tar.gz |
Switch HR_SI to HR_1000, make binary the default, make HR_B only affect bytes,
and update the tests.
Diffstat (limited to 'lib/lib.c')
-rw-r--r-- | lib/lib.c | 9 |
1 files changed, 4 insertions, 5 deletions
@@ -870,7 +870,7 @@ void names_to_pid(char **names, int (*callback)(pid_t pid, char *name)) int human_readable(char *buf, unsigned long long num, int style) { unsigned long long snap = 0; - int len, unit, divisor = (style&HR_SI) ? 1024 : 1000; + int len, unit, divisor = (style&HR_1000) ? 1000 : 1024; // Divide rounding up until we have 3 or fewer digits. Since the part we // print is decimal, the test is 999 even when we divide by 1024. @@ -879,7 +879,7 @@ int human_readable(char *buf, unsigned long long num, int style) for (unit = 0; num > 999; unit++) num = ((snap = num)+(divisor/2))/divisor; len = sprintf(buf, "%llu", num); if (unit && len == 1) { - // Redo rounding for 1.2M case, this works with HR_SI and not. + // Redo rounding for 1.2M case, this works with and without HR_1000. num = snap/divisor; snap -= num*divisor; snap = ((snap*100)+50)/divisor; @@ -890,10 +890,9 @@ int human_readable(char *buf, unsigned long long num, int style) if (unit) { unit = " kMGTPE"[unit]; - if (!(style&HR_SI)) unit = toupper(unit); + if (!(style&HR_1000)) unit = toupper(unit); buf[len++] = unit; - } - if (style & HR_B) buf[len++] = 'B'; + } else if (style & HR_B) buf[len++] = 'B'; buf[len] = 0; return len; |