diff options
| author | Federico Angelilli <code@fedang.net> | 2024-11-19 11:17:50 +0100 |
|---|---|---|
| committer | Federico Angelilli <code@fedang.net> | 2024-11-19 11:17:50 +0100 |
| commit | afcbe44a7cf454f3588a60180d93f65df9e5fcc7 (patch) | |
| tree | 7a3b94a9c9f7ef8cbd3062b26e31ef25b9d9a742 /src/util.h | |
| parent | 79a32360e76cb0739312e15299fc22941e51b64b (diff) | |
Add byte human readable formatting
Diffstat (limited to 'src/util.h')
| -rw-r--r-- | src/util.h | 15 |
1 files changed, 13 insertions, 2 deletions
@@ -5,6 +5,7 @@ #include <stddef.h> #include <stdbool.h> #include <stdio.h> +#include <stdint.h> #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 |
