Loading...
Searching...
No Matches
printf_helpers.h
/*
* Copyright (C) 2025 Kernkonzept GmbH.
* Author(s): Frank Mehnert <frank.mehnert@kernkonzept.com>
*
* License: see LICENSE.spdx (in this directory or the directories above)
*/
#pragma once
#include <stddef.h>
#include <stdio.h>
#include <l4/sys/compiler.h>
L4_INLINE int l4util_human_readable_size(char *outstr, size_t outsize,
unsigned long long bytes)
{
static char const *const unitstr = "BKMGT";
int idx = sizeof(unitstr) - 2;
int order;
for (order = idx * 10; order > 10; order -= 10, --idx)
if (bytes > (1ULL << order))
break;
unsigned long long value = bytes >> order;
unsigned long long fract = (bytes - (value << order))
/ ((1ULL << order) / 10 + 1);
return snprintf(outstr, outsize, "%llu.%1llu %ciB",
value, fract, unitstr[idx]);
}
compiler.h
L4 compiler related defines.
L4_INLINE
#define L4_INLINE
L4 Inline function attribute.
Definition compiler.h:51