diff options
-rw-r--r-- | include/libbb.h | 2 | ||||
-rw-r--r-- | libbb/human_readable.c | 23 | ||||
-rw-r--r-- | libbb/libbb.h | 2 |
3 files changed, 15 insertions, 12 deletions
diff --git a/include/libbb.h b/include/libbb.h index 4c23b2b80..b5c845952 100644 --- a/include/libbb.h +++ b/include/libbb.h | |||
@@ -201,7 +201,7 @@ struct sysinfo { | |||
201 | }; | 201 | }; |
202 | extern int sysinfo (struct sysinfo* info); | 202 | extern int sysinfo (struct sysinfo* info); |
203 | 203 | ||
204 | const char *make_human_readable_str(unsigned long val, unsigned long hr); | 204 | const char *make_human_readable_str(unsigned long val, unsigned long not_hr); |
205 | enum { | 205 | enum { |
206 | KILOBYTE = 1024, | 206 | KILOBYTE = 1024, |
207 | MEGABYTE = (KILOBYTE*1024), | 207 | MEGABYTE = (KILOBYTE*1024), |
diff --git a/libbb/human_readable.c b/libbb/human_readable.c index 1d7a90e55..36783fac7 100644 --- a/libbb/human_readable.c +++ b/libbb/human_readable.c | |||
@@ -31,20 +31,23 @@ | |||
31 | static char buffer[10]; | 31 | static char buffer[10]; |
32 | static const char *suffixes[] = { "", "k", "M", "G", "T" }; | 32 | static const char *suffixes[] = { "", "k", "M", "G", "T" }; |
33 | 33 | ||
34 | const char *make_human_readable_str(unsigned long val, unsigned long hr) | 34 | const char *make_human_readable_str(unsigned long val, unsigned long not_hr) |
35 | { | 35 | { |
36 | int suffix, base; | 36 | int suffix, base; |
37 | 37 | ||
38 | for (suffix = 0, base = 1; suffix < 5; suffix++, base <<= 10) { | 38 | if (not_hr) |
39 | if (val < (base << 10)) { | 39 | sprintf(buffer, "%lu", val); |
40 | if (suffix && val < 10 * base) | 40 | else |
41 | sprintf(buffer, "%lu.%lu%s", val / base, | 41 | for (suffix = 0, base = 1; suffix < 5; suffix++, base <<= 10) { |
42 | (val % base) * 10 / base, suffixes[suffix]); | 42 | if (val < (base << 10)) { |
43 | else | 43 | if (suffix && val < 10 * base) |
44 | sprintf(buffer, "%lu%s", val / base, suffixes[suffix]); | 44 | sprintf(buffer, "%lu.%lu%s", val / base, |
45 | break; | 45 | (val % base) * 10 / base, suffixes[suffix]); |
46 | else | ||
47 | sprintf(buffer, "%lu%s", val / base, suffixes[suffix]); | ||
48 | break; | ||
49 | } | ||
46 | } | 50 | } |
47 | } | ||
48 | 51 | ||
49 | return buffer; | 52 | return buffer; |
50 | } | 53 | } |
diff --git a/libbb/libbb.h b/libbb/libbb.h index 4c23b2b80..b5c845952 100644 --- a/libbb/libbb.h +++ b/libbb/libbb.h | |||
@@ -201,7 +201,7 @@ struct sysinfo { | |||
201 | }; | 201 | }; |
202 | extern int sysinfo (struct sysinfo* info); | 202 | extern int sysinfo (struct sysinfo* info); |
203 | 203 | ||
204 | const char *make_human_readable_str(unsigned long val, unsigned long hr); | 204 | const char *make_human_readable_str(unsigned long val, unsigned long not_hr); |
205 | enum { | 205 | enum { |
206 | KILOBYTE = 1024, | 206 | KILOBYTE = 1024, |
207 | MEGABYTE = (KILOBYTE*1024), | 207 | MEGABYTE = (KILOBYTE*1024), |