summaryrefslogtreecommitdiffstats
path: root/utils
diff options
context:
space:
mode:
Diffstat (limited to 'utils')
-rw-r--r--utils/common.c27
-rw-r--r--utils/common.h4
2 files changed, 28 insertions, 3 deletions
diff --git a/utils/common.c b/utils/common.c
index c42ce03..c6d1c34 100644
--- a/utils/common.c
+++ b/utils/common.c
@@ -38,7 +38,7 @@ jsonResponseFormatParse(const char *opt)
ssize_t
-glusterBlockCreateParseSize(const char *dom, char *value)
+glusterBlockParseSize(const char *dom, char *value)
{
char *postfix;
char *tmp;
@@ -85,6 +85,7 @@ glusterBlockCreateParseSize(const char *dom, char *value)
case 'k':
sizef *= 1024;
/* fall through */
+ case 'B':
case 'b':
case '\0':
return sizef;
@@ -96,3 +97,27 @@ glusterBlockCreateParseSize(const char *dom, char *value)
return -1;
}
}
+
+
+char *
+glusterBlockFormatSize(const char *dom, size_t bytes)
+{
+ char *buf;
+ size_t i = 0;
+ size_t rem = 0;
+ const char* units[] = {"B", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB", "YiB"};
+
+
+ while (bytes >= 1024) {
+ rem = (bytes % 1024);
+ bytes /= 1024;
+ i++;
+ }
+
+ if (GB_ASPRINTF(&buf, "%.1f %s", (float)bytes + (float)rem / 1024.0, units[i]) < 0) {
+ LOG(dom, GB_LOG_ERROR, "%s", "glusterBlockFormatSize() failed");
+ buf = NULL;
+ }
+
+ return buf;
+}
diff --git a/utils/common.h b/utils/common.h
index 21bf855..118d3f0 100644
--- a/utils/common.h
+++ b/utils/common.h
@@ -52,8 +52,8 @@ static const char *const JsonResponseFormatLookup[] = {
enum JsonResponseFormat jsonResponseFormatParse(const char *opt);
-int convertStringToTrillianParse(const char *opt);
+ssize_t glusterBlockParseSize(const char *dom, char *value);
-ssize_t glusterBlockCreateParseSize(const char *dom, char *value);
+char* glusterBlockFormatSize(const char *dom, size_t bytes);
# endif /* _COMMON_H */