X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?p=pintos-anon;a=blobdiff_plain;f=src%2Flib%2Fstdio.c;h=8927c50555d9993ae1ac952e21bc3fe7deb93f7e;hp=af80e51e527efc00897eae04ca6fe6642fd89d1b;hb=a03618133f7df0954802a470a4bee7674f7aed45;hpb=bb940d21474958a1d8ee2abffdcb6bac27918398 diff --git a/src/lib/stdio.c b/src/lib/stdio.c index af80e51..8927c50 100644 --- a/src/lib/stdio.c +++ b/src/lib/stdio.c @@ -635,3 +635,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", size, *fp); + } +}