aboutsummaryrefslogtreecommitdiffstats
path: root/fmt.c
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2024-09-21 19:31:16 +0200
committerMattias Andrée <maandree@kth.se>2024-09-21 19:31:16 +0200
commit2e55bedc45e836899a18ea7f4a488f50597afad5 (patch)
tree5a9e3cc1465cfc711fb1f74580cb17f20a46212e /fmt.c
parentUpdate documentation and adjust blocksize if larger than the device size (diff)
downloaddeadshred-2e55bedc45e836899a18ea7f4a488f50597afad5.tar.gz
deadshred-2e55bedc45e836899a18ea7f4a488f50597afad5.tar.bz2
deadshred-2e55bedc45e836899a18ea7f4a488f50597afad5.tar.xz
misc
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'fmt.c')
-rw-r--r--fmt.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/fmt.c b/fmt.c
index 4c931dd..7b73ed7 100644
--- a/fmt.c
+++ b/fmt.c
@@ -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;
+}