From 960100aa9cb588a73125d43ec0b0a7152a95b43f Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Sun, 6 Sep 2015 20:10:04 -0500 Subject: Switch HR_SI to HR_1000, make binary the default, make HR_B only affect bytes, and update the tests. --- lib/lib.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'lib/lib.c') diff --git a/lib/lib.c b/lib/lib.c index 27305ec9..058c6386 100644 --- a/lib/lib.c +++ b/lib/lib.c @@ -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; -- cgit v1.2.3