aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThorsten Töpper <atsutane@freethoughts.de>2025-07-26 03:33:12 +0200
committerThorsten Töpper <atsutane@freethoughts.de>2025-07-26 03:33:12 +0200
commit9965731cdc7887ad25142a8799c26aafb75fa00f (patch)
treec94b27f16cdf4886f41443ad08c35e964d853ffd /src
parentff1bd6be03e2a0b12309b074dd0c13c6cc6c0ca6 (diff)
downloaddir_monitor-9965731cdc7887ad25142a8799c26aafb75fa00f.tar.gz
dir_monitor-9965731cdc7887ad25142a8799c26aafb75fa00f.tar.bz2
output: size unit MiB for files larger 10 GiB
Diffstat (limited to 'src')
-rw-r--r--src/output.c18
1 files changed, 15 insertions, 3 deletions
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':