ls: add -h flag

for util/human don't show "B" for bytes.
This commit is contained in:
Hiltjo Posthuma
2014-10-19 09:48:04 +00:00
committed by sin
parent 2cf82f4c16
commit 4d4e2608c1
3 changed files with 16 additions and 5 deletions

View File

@@ -7,14 +7,14 @@ char *
humansize(double n)
{
static char buf[16];
const char postfixes[] = " KMGTPE";
const char postfixes[] = "BKMGTPE";
size_t i;
for(i = 0; n >= 1024 && i < strlen(postfixes); i++)
n /= 1024;
if(!i)
snprintf(buf, sizeof(buf), "%lu%c", (unsigned long)n, postfixes[i]);
snprintf(buf, sizeof(buf), "%lu", (unsigned long)n);
else
snprintf(buf, sizeof(buf), "%.1f%c", n, postfixes[i]);
return buf;