diff options
author | Mattias Andrée <maandree@kth.se> | 2024-09-21 19:31:16 +0200 |
---|---|---|
committer | Mattias Andrée <maandree@kth.se> | 2024-09-21 19:31:16 +0200 |
commit | 2e55bedc45e836899a18ea7f4a488f50597afad5 (patch) | |
tree | 5a9e3cc1465cfc711fb1f74580cb17f20a46212e /fmt.c | |
parent | Update documentation and adjust blocksize if larger than the device size (diff) | |
download | deadshred-2e55bedc45e836899a18ea7f4a488f50597afad5.tar.gz deadshred-2e55bedc45e836899a18ea7f4a488f50597afad5.tar.bz2 deadshred-2e55bedc45e836899a18ea7f4a488f50597afad5.tar.xz |
misc
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to '')
-rw-r--r-- | fmt.c | 16 |
1 files changed, 16 insertions, 0 deletions
@@ -187,3 +187,19 @@ humanbytespersecond(double bytes_per_second, char *buf) return buf; } + + +const char * +exact_and_human_size(off_t bytes, char *buf, int with_unit) +{ + char *p = buf; + p += sprintf(p, "%ji%s", (intmax_t)bytes, !with_unit ? "" : bytes == 1 ? " byte" : " bytes"); + if (bytes >= 1024) { + p = stpcpy(p, " ("); + humansize1000(bytes, p); + p = stpcpy(strchr(p, '\0'), ", "); + humansize1024(bytes, p); + p = stpcpy(strchr(p, '\0'), ")"); + } + return buf; +} |