size -= n;
}
}
+
+/* Prints SIZE, which represents a number of bytes, in a
+ human-readable format, e.g. "256 kB". */
+void
+print_human_readable_size (uint64_t size)
+{
+ if (size == 1)
+ printf ("1 byte");
+ else
+ {
+ static const char *factors[] = {"bytes", "kB", "MB", "GB", "TB", NULL};
+ const char **fp;
+
+ for (fp = factors; size >= 1024 && fp[1] != NULL; fp++)
+ size /= 1024;
+ printf ("%"PRIu64" %s", *fp);
+ }
+}
int vhprintf (int, const char *, va_list) PRINTF_FORMAT (2, 0);
#endif
void hex_dump (uintptr_t ofs, const void *, size_t size, bool ascii);
+void print_human_readable_size (uint64_t size);
/* Internal functions. */
void __vprintf (const char *format, va_list args,