From 9965731cdc7887ad25142a8799c26aafb75fa00f Mon Sep 17 00:00:00 2001 From: Thorsten Töpper Date: Sat, 26 Jul 2025 03:33:12 +0200 Subject: output: size unit MiB for files larger 10 GiB --- src/output.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'src/output.c') diff --git a/src/output.c b/src/output.c index 644a6a6..8e57bcd 100644 --- a/src/output.c +++ b/src/output.c @@ -194,8 +194,20 @@ inline void out_print_user_name(struct list_node *ptr) { } inline void out_print_size(struct list_node *ptr) { - printf(" %8ld %2s ", ((ptr->ln_stat.st_size>=1024) ? (ptr->ln_stat.st_size/1024) : ptr->ln_stat.st_size), - ((ptr->ln_stat.st_size >= 1024) ? "kB" : "")); + char unit[4] = ""; + off_t tmp = ptr->ln_stat.st_size; + if (tmp >= 1024) { + tmp /= 1024; + unit[0] = 'K'; + unit[1] = 'i'; + unit[2] = 'B'; + /* > 10 GiB as MiB */ + if (tmp > (10*1024*1024)) { + tmp /= 1024; + unit[0] = 'M'; + } + } + printf(" %8ld %3s ", tmp, unit); } inline void out_print_time(time_t tv) { @@ -399,7 +411,7 @@ inline void out_print_format_string_header(const char *format, size_t longest_fn LOCAL_EXTEND_SEP_LINE(); break; case 's': - sprintf(pos, " %11s ", "SIZE "); + sprintf(pos, " %12s ", "SIZE "); LOCAL_EXTEND_SEP_LINE(); break; case 't': -- cgit v1.2.3-70-g09d2