aboutsummaryrefslogtreecommitdiff
path: root/toys/posix
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2016-08-25 16:28:05 -0700
committerRob Landley <rob@landley.net>2016-08-27 21:51:56 -0500
commitf9da4355525d4e5229788b0dc53a291cfc76bfe5 (patch)
tree86e17e6d8203d72eddeb39b6b08df881e0828355 /toys/posix
parenta87b65c371aadee6a239f231e3d9ed1b390c630b (diff)
downloadtoybox-f9da4355525d4e5229788b0dc53a291cfc76bfe5.tar.gz
Fix ls -sh.
-h should apply to -s too. (Previously it only applied to the "total" line in -s output.)
Diffstat (limited to 'toys/posix')
-rw-r--r--toys/posix/ls.c20
1 files 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;