aboutsummaryrefslogtreecommitdiff
path: root/src/util.h
diff options
context:
space:
mode:
authorFederico Angelilli <code@fedang.net>2024-11-19 11:17:50 +0100
committerFederico Angelilli <code@fedang.net>2024-11-19 11:17:50 +0100
commitafcbe44a7cf454f3588a60180d93f65df9e5fcc7 (patch)
tree7a3b94a9c9f7ef8cbd3062b26e31ef25b9d9a742 /src/util.h
parent79a32360e76cb0739312e15299fc22941e51b64b (diff)
Add byte human readable formatting
Diffstat (limited to 'src/util.h')
-rw-r--r--src/util.h15
1 files changed, 13 insertions, 2 deletions
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 <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