X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Flib%2Fstdio.c;h=3549d4e9fd70f854880cb9a87cc26bfcee8f91d4;hb=4419844a889e14a9d7b08205a41b7d97fe4b2bfc;hp=98b63030b4d2925127b77f14b4f8a1394fa61066;hpb=9890d47f4dba4ab2784a4ed5d424cddf697cfe18;p=pintos-anon diff --git a/src/lib/stdio.c b/src/lib/stdio.c index 98b6303..3549d4e 100644 --- a/src/lib/stdio.c +++ b/src/lib/stdio.c @@ -608,3 +608,21 @@ hex_dump (uintptr_t ofs, const void *buf_, size_t size, bool ascii) 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); + } +}