-struct unit {
- const char *name;
- int m;
-};
-
-static void prhuman_time(FILE *fp, unsigned long n)
-{
- const static struct unit utime[] = {
- { "s", 60 }, { "m", 60 }, { "h", 24 }, { "d", 0 }
- };
-
- unsigned long m = 0;
- const struct unit *u = utime;
-
- while (u[1].m && n > u[0].m*u[1].m) { n /= u->m; u++; }
- m = n / u[1].m; n %= u[0].m;
- if (m) fprintf(fp, "%3lu%s%02lu%s", m, u[1].name, n, u[0].name);
- else fprintf(fp, " %2lu%s", n, u[0].name);
-}
-
-static void prhuman_data(FILE *fp, off_t n)
-{
- const static struct unit udata[] = {
- { " ", 1024 }, { "k", 1024 }, { "M", 1024 }, { "G", 1024 },
- { "T", 1024 }, { "P", 1024 }, { "E", 1024 }, { "Z", 1024 },
- { "Y", 0 }
- };
-
- double x = n;
- const struct unit *u = udata;
-
- while (u->m && x >= u->m) { x /= u->m; u++; }
- fprintf(fp, "%6.1f%s", x, u->name);
-}
-