aboutsummaryrefslogtreecommitdiff
path: root/libsylph
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
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')
-rw-r--r--libsylph/libsylph-0.def1
-rw-r--r--libsylph/utils.c21
-rw-r--r--libsylph/utils.h3
3 files changed, 17 insertions, 8 deletions
diff --git a/libsylph/libsylph-0.def b/libsylph/libsylph-0.def
index 80ee21c6..5c55c850 100644
--- a/libsylph/libsylph-0.def
+++ b/libsylph/libsylph-0.def
@@ -696,3 +696,4 @@ EXPORTS
filter_junk_rule_create @ 694
folder_remote_folder_active_session_exist @ 695
procmsg_add_messages_from_queue @ 696
+ to_human_readable_buf @ 697
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 */
diff --git a/libsylph/utils.h b/libsylph/utils.h
index 200f03b3..14b289be 100644
--- a/libsylph/utils.h
+++ b/libsylph/utils.h
@@ -225,6 +225,9 @@ gchar *itos_buf (gchar *nstr,
gchar *itos (gint n);
gchar *utos_buf (gchar *nstr,
guint n);
+gchar *to_human_readable_buf (gchar *buf,
+ size_t bufsize,
+ gint64 size);
gchar *to_human_readable (gint64 size);
/* alternative string functions */