summaryrefslogtreecommitdiffstats
path: root/libglusterfs/src/common-utils.c
diff options
context:
space:
mode:
authorJunaid <junaid@gluster.com>2011-06-14 03:28:40 +0000
committerAnand Avati <avati@gluster.com>2011-06-14 09:04:22 -0700
commit6ae674eef777fda74191e2186d95778b9d5671f3 (patch)
tree5a606c68ae60467639940a09110fcdd35432a8d0 /libglusterfs/src/common-utils.c
parenta383d5b22aae9837f5609f304ee0488bcf8bafba (diff)
libglusterfs/common-utils: Added gf_uint64_2human_readable function.
This function converts the given number to its corresponding representation in KB, MB, etc. Signed-off-by: Junaid <junaid@gluster.com> Signed-off-by: Anand Avati <avati@gluster.com> BUG: 2829 (Display the quota limit as it is configured) URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=2829
Diffstat (limited to 'libglusterfs/src/common-utils.c')
-rw-r--r--libglusterfs/src/common-utils.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/libglusterfs/src/common-utils.c b/libglusterfs/src/common-utils.c
index 29af725a07a..15371d1941f 100644
--- a/libglusterfs/src/common-utils.c
+++ b/libglusterfs/src/common-utils.c
@@ -1262,6 +1262,42 @@ gf_string2uint64_base10 (const char *str, uint64_t *n)
return -1;
}
+char *
+gf_uint64_2human_readable (uint64_t n)
+{
+ int ret = 0;
+ char *str = NULL;
+
+ if (n >= GF_UNIT_PB) {
+ ret = gf_asprintf (&str, "%.1lfPB", ((double) n)/GF_UNIT_PB);
+ if (ret < 0)
+ goto err;
+ } else if (n >= GF_UNIT_TB) {
+ ret = gf_asprintf (&str, "%.1lfTB", ((double) n)/GF_UNIT_TB);
+ if (ret < 0)
+ goto err;
+ } else if (n >= GF_UNIT_GB) {
+ ret = gf_asprintf (&str, "%.1lfGB", ((double) n)/GF_UNIT_GB);
+ if (ret < 0)
+ goto err;
+ } else if (n >= GF_UNIT_MB) {
+ ret = gf_asprintf (&str, "%.1lfMB", ((double) n)/GF_UNIT_MB);
+ if (ret < 0)
+ goto err;
+ } else if (n >= GF_UNIT_KB) {
+ ret = gf_asprintf (&str, "%.1lfKB", ((double) n)/GF_UNIT_KB);
+ if (ret < 0)
+ goto err;
+ } else {
+ ret = gf_asprintf (&str, "%luBytes", n);
+ if (ret < 0)
+ goto err;
+ }
+ return str;
+err:
+ return NULL;
+}
+
int
gf_string2bytesize (const char *str, uint64_t *n)
{