aboutsummaryrefslogtreecommitdiffstats
path: root/fmt.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-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;
+}