From f9da4355525d4e5229788b0dc53a291cfc76bfe5 Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Thu, 25 Aug 2016 16:28:05 -0700 Subject: Fix ls -sh. -h should apply to -s too. (Previously it only applied to the "total" line in -s output.) --- toys/posix/ls.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/toys/posix/ls.c b/toys/posix/ls.c index d48fb831..c7e2da5a 100644 --- a/toys/posix/ls.c +++ b/toys/posix/ls.c @@ -149,12 +149,17 @@ static void entrylen(struct dirtree *dt, unsigned *len) // tracking another column len[5] = numlen(dev_major(st->st_rdev))+5; } else if (flags & FLAG_h) { - human_readable(tmp, st->st_size, 0); - len[5] = strwidth(tmp); + human_readable(tmp, st->st_size, 0); + len[5] = strwidth(tmp); } else len[5] = numlen(st->st_size); } - len[6] = (flags & FLAG_s) ? numlen(st->st_blocks) : 0; + if (flags & FLAG_s) { + if (flags & FLAG_h) { + human_readable(tmp, st->st_blocks*512, 0); + len[6] = strwidth(tmp); + } else len[6] = numlen(st->st_blocks); + } else len[6] = 0; len[7] = (flags & FLAG_Z) ? strwidth((char *)dt->extra) : 0; } @@ -424,8 +429,13 @@ static void listfiles(int dirfd, struct dirtree *indir) if (flags & FLAG_i) xprintf("%*lu ", totals[1], (unsigned long)st->st_ino); - if (flags & FLAG_s) - xprintf("%*lu ", totals[6], (unsigned long)st->st_blocks); + + if (flags & FLAG_s) { + if (flags & FLAG_h) { + human_readable(tmp, st->st_blocks*512, 0); + xprintf("%*s ", totals[6], tmp); + } else xprintf("%*lu ", totals[6], (unsigned long)st->st_blocks); + } if (flags & (FLAG_l|FLAG_o|FLAG_n|FLAG_g)) { struct tm *tm; -- cgit v1.2.3