summaryrefslogtreecommitdiffstats
path: root/src/libnetdata/parsers/size.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/libnetdata/parsers/size.h')
-rw-r--r--src/libnetdata/parsers/size.h20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/libnetdata/parsers/size.h b/src/libnetdata/parsers/size.h
new file mode 100644
index 000000000..6abfe7235
--- /dev/null
+++ b/src/libnetdata/parsers/size.h
@@ -0,0 +1,20 @@
+// SPDX-License-Identifier: GPL-3.0-or-later
+
+#ifndef LIBNETDATA_PARSERS_SIZE_H
+#define LIBNETDATA_PARSERS_SIZE_H
+
+#include "parsers.h"
+
+bool size_parse(const char *size_str, uint64_t *result, const char *default_unit);
+#define size_parse_bytes(size_str, bytes) size_parse(size_str, bytes, "B")
+#define size_parse_kb(size_str, kb) size_parse(size_str, kb, "KiB")
+#define size_parse_mb(size_str, mb) size_parse(size_str, mb, "MiB")
+#define size_parse_gb(size_str, gb) size_parse(size_str, gb, "GiB")
+
+ssize_t size_snprintf(char *dst, size_t dst_size, uint64_t value, const char *unit, bool accurate);
+#define size_snprintf_bytes(dst, dst_size, value) size_snprintf(dst, dst_size, value, "B", true)
+#define size_snprintf_kb(dst, dst_size, value) size_snprintf(dst, dst_size, value, "KiB", true)
+#define size_snprintf_mb(dst, dst_size, value) size_snprintf(dst, dst_size, value, "MiB", true)
+#define size_snprintf_gb(dst, dst_size, value) size_snprintf(dst, dst_size, value, "GiB", true)
+
+#endif //LIBNETDATA_PARSERS_SIZE_H