diff options
Diffstat (limited to 'fmt.c')
-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; +} |