summaryrefslogtreecommitdiffstats
path: root/src/libnetdata/parsers/size.h
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-11-25 17:33:56 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-11-25 17:34:10 +0000
commit83ba6762cc43d9db581b979bb5e3445669e46cc2 (patch)
tree2e69833b43f791ed253a7a20318b767ebe56cdb8 /src/libnetdata/parsers/size.h
parentReleasing debian version 1.47.5-1. (diff)
downloadnetdata-83ba6762cc43d9db581b979bb5e3445669e46cc2.tar.xz
netdata-83ba6762cc43d9db581b979bb5e3445669e46cc2.zip
Merging upstream version 2.0.3+dfsg (Closes: #923993, #1042533, #1045145).
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
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