From afcbe44a7cf454f3588a60180d93f65df9e5fcc7 Mon Sep 17 00:00:00 2001 From: Federico Angelilli Date: Tue, 19 Nov 2024 11:17:50 +0100 Subject: Add byte human readable formatting --- src/util.h | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'src/util.h') diff --git a/src/util.h b/src/util.h index 5f58a79..8d60eb2 100644 --- a/src/util.h +++ b/src/util.h @@ -5,6 +5,7 @@ #include #include #include +#include #define unreachable() log_panic("The impossible happened"); @@ -67,10 +68,20 @@ bool strfind(const char *string, const char *cases[]); size_t strprefix(const char *string, const char *prefix); -char *strformat(const char *string, char delim, const char *keys[], const char *values[]); - void strfree(char **list); bool iszero(const void *ptr, size_t size); +typedef enum { + UNIT_B = 1 << 0, + UNIT_KB = 1 << 1, + UNIT_MB = 1 << 2, + UNIT_GB = 1 << 3, + UNIT_TB = 1 << 4, + UNIT_SI = 1 << 5, + UNIT_MASK = UNIT_B | UNIT_KB | UNIT_MB | UNIT_GB | UNIT_TB | UNIT_SI, +} unit_t; + +int snprintf_units(char *buffer, size_t max, uint64_t bytes, unit_t unit); + #endif -- cgit v1.2.3