From 5b7cc6d6c2a549188ce652d44b2583c01fb48188 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Sat, 12 Sep 2020 07:46:44 -0500 Subject: Replace HR_COMMAS with HR_NODOT The comma thing turned into an internationalization can of worms, don't go there. Keep the "show megabytes on systems with >10G" logic which includes not showing 0.0 for single digit values. --- lib/lib.c | 29 ++++------------------------- 1 file changed, 4 insertions(+), 25 deletions(-) (limited to 'lib/lib.c') diff --git a/lib/lib.c b/lib/lib.c index 319b6af4..752fd0a1 100644 --- a/lib/lib.c +++ b/lib/lib.c @@ -1151,48 +1151,27 @@ match: int human_readable_long(char *buf, unsigned long long num, int dgt, int unit, int style) { - static char cc, dot; unsigned long long snap = 0; - int len, commas = 0, off, ii, divisor = (style&HR_1000) ? 1000 : 1024; + int len, 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. // The largest unit we can detect is 1<<64 = 18 Exabytes, but we added // Zettabyte and Yottabyte in case "unit" starts above zero. for (;;unit++) { - len = snprintf(0, 0, "%llu", num); - if (style&HR_COMMAS) commas = (len-1)/3; - if (len<=(dgt-commas)) break; + if ((len = snprintf(0, 0, "%llu", num))<=dgt) break; num = ((snap = num)+(divisor/2))/divisor; } if (CFG_TOYBOX_DEBUG && unit>8) return sprintf(buf, "%.*s", dgt, "TILT"); - if (!dot) { - if (CFG_TOYBOX_I18N) { - struct lconv *ll; - - setlocale(LC_NUMERIC, ""); - ll = localeconv(); - dot = *ll->decimal_point ? : '.'; - cc = *ll->thousands_sep ? : ','; - } else cc = ',', dot = '.'; - } - len = sprintf(buf, "%llu", num); - if (style&HR_COMMAS) { - for (ii = 0; ii