← Commit list

ff8fda848

Denys Vlasenko
Denys Vlasenko
2022-01-08
SUCCESS Duration: 154s

Subject

ls: implement ls -sh (human-readable allocated blocks)

Binary

No binary (build failed)

Architecture & Compiler Flags

Architecture: x86_64-linux-gnu Compiler: gcc (Ubuntu 11.4.0-1ubuntu1~22.04.3) 11.4.0

—

Build Log

(log yok)

Commit Diff GitHub →

coreutils/ls.c+10 -3
@@ -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];