diff options
Diffstat (limited to 'libbb/human_readable.c')
-rw-r--r-- | libbb/human_readable.c | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/libbb/human_readable.c b/libbb/human_readable.c index 1d7a90e..36783fa 100644 --- a/libbb/human_readable.c +++ b/libbb/human_readable.c @@ -31,20 +31,23 @@ static char buffer[10]; static const char *suffixes[] = { "", "k", "M", "G", "T" }; -const char *make_human_readable_str(unsigned long val, unsigned long hr) +const char *make_human_readable_str(unsigned long val, unsigned long not_hr) { int suffix, base; - for (suffix = 0, base = 1; suffix < 5; suffix++, base <<= 10) { - if (val < (base << 10)) { - if (suffix && val < 10 * base) - sprintf(buffer, "%lu.%lu%s", val / base, - (val % base) * 10 / base, suffixes[suffix]); - else - sprintf(buffer, "%lu%s", val / base, suffixes[suffix]); - break; + if (not_hr) + sprintf(buffer, "%lu", val); + else + for (suffix = 0, base = 1; suffix < 5; suffix++, base <<= 10) { + if (val < (base << 10)) { + if (suffix && val < 10 * base) + sprintf(buffer, "%lu.%lu%s", val / base, + (val % base) * 10 / base, suffixes[suffix]); + else + sprintf(buffer, "%lu%s", val / base, suffixes[suffix]); + break; + } } - } return buffer; } |