31L4_INLINE int l4util_human_readable_size(
char *outstr,
size_t outsize,
32 unsigned long long bytes)
34 static char const unitstr[7] = {
'B',
'K',
'M',
'G',
'T',
'P',
'E' };
36 int idx =
sizeof(unitstr) - 1;
39 for (order = idx * 10; order >= 10; order -= 10, --idx)
40 if (bytes > (1ULL << order))
43 unsigned long long value = bytes >> order;
44 unsigned long long fract = (bytes - (value << order))
45 / ((1ULL << order) / 10 + 1);
48 return snprintf(outstr, outsize,
"%llu.%1llu %ciB",
49 value, fract, unitstr[idx]);
51 return snprintf(outstr, outsize,
"%llu B ", value);
75L4_INLINE int l4util_human_readable_size_region(
char *outstr,
size_t outsize,
76 unsigned long long begin,
77 unsigned long long end)
79 if (end - begin == ~0UL)
80 return snprintf(outstr, outsize,
"%s",
81 sizeof(
long) == 4 ?
"4.0 GiB" :
"16.0 EiB");
83 return l4util_human_readable_size(outstr, outsize, end - begin + 1);
L4 compiler related defines.
#define L4_INLINE
L4 Inline function attribute.