Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.busybox.net/busybox.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2022-01-09 00:59:49 +0300
committerDenys Vlasenko <vda.linux@googlemail.com>2022-01-09 00:59:49 +0300
commitff8fda848284e82d97299806b31c196651b372a5 (patch)
tree06a35dd78553d004563f9179a7034669f7938a8d /coreutils
parent143356876b5712c28b8af61ea9144959a4dc6a5b (diff)
ls: implement ls -sh (human-readable allocated blocks)
function old new delta display_single 979 1018 +39 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'coreutils')
-rw-r--r--coreutils/ls.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/coreutils/ls.c b/coreutils/ls.c
index 48f5eb482..b69b80460 100644
--- a/coreutils/ls.c
+++ b/coreutils/ls.c
@@ -498,9 +498,16 @@ static NOINLINE unsigned display_single(const struct dnode *dn)
if (opt & OPT_i) /* show inode# */
column += printf("%7llu ", (long long) dn->dn_ino);
-//TODO: -h should affect -s too:
- if (opt & OPT_s) /* show allocated blocks */
- column += printf("%6"OFF_FMT"u ", (off_t) (dn->dn_blocks >> 1));
+ if (opt & OPT_s) { /* show allocated blocks */
+ if (opt & OPT_h) {
+ column += printf("%"HUMAN_READABLE_MAX_WIDTH_STR"s ",
+ /* print size, show one fractional, use suffixes */
+ make_human_readable_str((off_t)dn->dn_blocks << 9, 1, 0)
+ );
+ } else {
+ column += printf("%6"OFF_FMT"u ", (off_t)(dn->dn_blocks >> 1));
+ }
+ }
if (opt & OPT_l) {
/* long listing: show mode */
char modestr[12];