Implement a proper block layer with partition support.
[pintos-anon] / src / lib / stdio.c
index e09401a61028cee158e588c4b12bc3c5d3fe5aea..8927c50555d9993ae1ac952e21bc3fe7deb93f7e 100644 (file)
@@ -515,7 +515,7 @@ format_integer (uintmax_t value, bool is_signed, bool negative,
   /* Append enough zeros to match precision.
      If requested precision is 0, then a value of zero is
      rendered as a null string, otherwise as "0".
-     If the # flag is used with base 0, the result must always
+     If the # flag is used with base 8, the result must always
      begin with a zero. */
   precision = c->precision < 0 ? 1 : c->precision;
   while (cp - buf < precision && cp < buf + sizeof buf - 1)
@@ -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);
+    }
+}