aboutsummaryrefslogtreecommitdiff
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
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
-rw-r--r--ChangeLog4
-rw-r--r--libsylph/libsylph-0.def1
-rw-r--r--libsylph/utils.c21
-rw-r--r--libsylph/utils.h3
-rw-r--r--src/inc.c9
-rw-r--r--src/mimeview.c5
6 files changed, 25 insertions, 18 deletions
diff --git a/ChangeLog b/ChangeLog
index a3f264ea..8864eb33 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -4,7 +4,9 @@
src/textview.c: fixed a typo: mimeview_launch_part() and code
cleanups. Removed alloca() call.
* src/summaryview.c
- src/messageview.c: removed alloca() calls.
+ src/messageview.c
+ src/inc.c: removed alloca() calls.
+ * libsylph/utils.[ch]: to_human_readable_buf(): new.
2011-06-16
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 */
diff --git a/src/inc.c b/src/inc.c
index 5ac069a5..661aa394 100644
--- a/src/inc.c
+++ b/src/inc.c
@@ -1029,7 +1029,6 @@ static void inc_progress_dialog_set_progress(IncProgressDialog *inc_dialog,
{
gchar buf[BUFFSIZE];
Pop3Session *pop3_session = POP3_SESSION(inc_session->session);
- gchar *total_size_str;
gint64 cur_total;
gint64 total;
gint cur_num;
@@ -1050,7 +1049,10 @@ static void inc_progress_dialog_set_progress(IncProgressDialog *inc_dialog,
if ((pop3_session->state == POP3_RETR ||
pop3_session->state == POP3_RETR_RECV ||
pop3_session->state == POP3_DELETE) && total_num_to_recv > 0) {
- Xstrdup_a(total_size_str, to_human_readable(total), return);
+ gchar total_size_str[16];
+
+ to_human_readable_buf(total_size_str, sizeof(total_size_str),
+ total);
g_snprintf(buf, sizeof(buf),
_("Retrieving message (%d / %d) (%s / %s)"),
cur_num, total_num_to_recv,
@@ -1079,8 +1081,7 @@ static void inc_progress_dialog_set_progress(IncProgressDialog *inc_dialog,
g_snprintf(buf, sizeof(buf),
_("%d message(s) (%s) received"),
pop3_session->cur_total_num,
- to_human_readable
- (pop3_session->cur_total_recv_bytes));
+ to_human_readable(pop3_session->cur_total_recv_bytes));
progress_dialog_set_row_progress(inc_dialog->dialog,
inc_dialog->cur_row, buf);
}
diff --git a/src/mimeview.c b/src/mimeview.c
index fffd508a..1fa10517 100644
--- a/src/mimeview.c
+++ b/src/mimeview.c
@@ -1061,8 +1061,6 @@ static void mimeview_display_as_text(MimeView *mimeview)
void mimeview_save_as(MimeView *mimeview)
{
- gchar *filename;
- gchar *defname = NULL;
MimeInfo *partinfo;
if (!mimeview->opened) return;
@@ -1212,7 +1210,6 @@ void mimeview_save_part_as(MimeView *mimeview, MimeInfo *partinfo)
static void mimeview_launch(MimeView *mimeview)
{
MimeInfo *partinfo;
- gchar *filename;
if (!mimeview->opened) return;
if (!mimeview->file) return;
@@ -1226,8 +1223,6 @@ static void mimeview_launch(MimeView *mimeview)
static void mimeview_open_with(MimeView *mimeview)
{
MimeInfo *partinfo;
- gchar *filename;
- gchar *cmd;
if (!mimeview->opened) return;
if (!mimeview->file) return;