+static void compute_display_size(unsigned long long size,
+ const char **fmt, double *display_size)
+{
+ static const char *const fmts[] = {
+ "%g b", "%g Kb", "%#.1f Mb", "%#.1f Gb", "%#.1f Tb",
+ "%#.1f Pb", "%#.1f Eb", "%#.1f Zb", "%#.1f Yb"
+ };
+ int shift = 0;
+
+ while (size >= 1024 && shift < lenof(fmts)-1) {
+ size >>= 10;
+ shift++;
+ }
+ *display_size = (double)size;
+ *fmt = fmts[shift];
+}
+