aboutsummaryrefslogtreecommitdiff
path: root/libsylph/utils.c
diff options
context:
space:
mode:
authorhiro <hiro@ee746299-78ed-0310-b773-934348b2243d>2011-06-23 06:15:25 +0000
committerhiro <hiro@ee746299-78ed-0310-b773-934348b2243d>2011-06-23 06:15:25 +0000
commitc36140823bb2b5a3c7013970748a8cef832e2ce3 (patch)
tree619a5b2d104fb7b7393776ac800ef967947c0294 /libsylph/utils.c
parentafa9a51b3aaabe150ebebc67bd63fdaf5f558d67 (diff)
libsylph/utils.[ch]: to_human_readable_buf(): new.
git-svn-id: svn://sylpheed.sraoss.jp/sylpheed/trunk@2909 ee746299-78ed-0310-b773-934348b2243d
Diffstat (limited to 'libsylph/utils.c')
-rw-r--r--libsylph/utils.c21
1 files changed, 13 insertions, 8 deletions
diff --git a/libsylph/utils.c b/libsylph/utils.c
index ac51271c..18c9917c 100644
--- a/libsylph/utils.c
+++ b/libsylph/utils.c
@@ -354,20 +354,25 @@ gchar *utos_buf(gchar *nstr, guint n)
return nstr;
}
-gchar *to_human_readable(gint64 size)
+gchar *to_human_readable_buf(gchar *buf, size_t bufsize, gint64 size)
{
- static gchar str[16];
-
if (size < 1024)
- g_snprintf(str, sizeof(str), "%dB", (gint)size);
+ g_snprintf(buf, bufsize, "%dB", (gint)size);
else if ((size >> 10) < 1024)
- g_snprintf(str, sizeof(str), "%.1fKB", (gfloat)size / (1 << 10));
+ g_snprintf(buf, bufsize, "%.1fKB", (gfloat)size / (1 << 10));
else if ((size >> 20) < 1024)
- g_snprintf(str, sizeof(str), "%.2fMB", (gfloat)size / (1 << 20));
+ g_snprintf(buf, bufsize, "%.2fMB", (gfloat)size / (1 << 20));
else
- g_snprintf(str, sizeof(str), "%.2fGB", (gfloat)size / (1 << 30));
+ g_snprintf(buf, bufsize, "%.2fGB", (gfloat)size / (1 << 30));
- return str;
+ return buf;
+}
+
+gchar *to_human_readable(gint64 size)
+{
+ static gchar str[16];
+
+ return to_human_readable_buf(str, sizeof(str), size);
}
/* strcmp with NULL-checking */