diff options
author | hiro <hiro@ee746299-78ed-0310-b773-934348b2243d> | 2010-01-13 03:44:57 +0000 |
---|---|---|
committer | hiro <hiro@ee746299-78ed-0310-b773-934348b2243d> | 2010-01-13 03:44:57 +0000 |
commit | 9f827874227532e3cfa58c3f1b7e4822ac1add70 (patch) | |
tree | 700f63ab4bdf896a8d41b9c5ffac233b3fb0c56f | |
parent | fb375b0408b0b62b79ea6ebf659661253e54d8fd (diff) |
remove_numbered_files(): made filename to number conversion unsigned (fixes undeleted IMAP caches with UIDs larger than INT_MAX).
git-svn-id: svn://sylpheed.sraoss.jp/sylpheed/trunk@2422 ee746299-78ed-0310-b773-934348b2243d
-rw-r--r-- | ChangeLog | 7 | ||||
-rw-r--r-- | libsylph/libsylph-0.def | 1 | ||||
-rw-r--r-- | libsylph/utils.c | 26 | ||||
-rw-r--r-- | libsylph/utils.h | 1 |
4 files changed, 31 insertions, 4 deletions
@@ -4,6 +4,13 @@ 2010-01-13 + * libsylph/utils.c: to_unumber(): added. + remove_numbered_files() + remove_expired_files(): made filename to number conversion unsigned + (fixes undeleted IMAP caches with UIDs larger than INT_MAX). + +2010-01-13 + * libsylph/imap.c: imap_cmd_append(): added date-time info on APPEND using Date: header (for Gmail to display received date). diff --git a/libsylph/libsylph-0.def b/libsylph/libsylph-0.def index 55f43a52..efbfa298 100644 --- a/libsylph/libsylph-0.def +++ b/libsylph/libsylph-0.def @@ -672,3 +672,4 @@ EXPORTS strcasestr_with_skip_quote @ 670
is_path_parent @ 671
extract_addresses @ 672
+ to_unumber @ 673
diff --git a/libsylph/utils.c b/libsylph/utils.c index e9eba77a..6abbefa2 100644 --- a/libsylph/utils.c +++ b/libsylph/utils.c @@ -314,6 +314,24 @@ gint to_number(const gchar *nstr) return atoi(nstr); } +guint to_unumber(const gchar *nstr) +{ + register const gchar *p; + gulong val; + + if (*nstr == '\0') return -1; + + for (p = nstr; *p != '\0'; p++) + if (!g_ascii_isdigit(*p)) return -1; + + errno = 0; + val = strtoul(nstr, NULL, 10); + if (val == ULONG_MAX && errno != 0) + val = 0; + + return (guint)val; +} + /* convert integer into string, nstr must be not lower than 11 characters length */ gchar *itos_buf(gchar *nstr, gint n) @@ -2570,7 +2588,7 @@ gint remove_numbered_files(const gchar *dir, guint first, guint last) GDir *dp; const gchar *dir_name; gchar *prev_dir; - gint file_no; + guint file_no; prev_dir = g_get_current_dir(); @@ -2587,7 +2605,7 @@ gint remove_numbered_files(const gchar *dir, guint first, guint last) } while ((dir_name = g_dir_read_name(dp)) != NULL) { - file_no = to_number(dir_name); + file_no = to_unumber(dir_name); if (file_no > 0 && first <= file_no && file_no <= last) { if (is_dir_exist(dir_name)) continue; @@ -2620,7 +2638,7 @@ gint remove_expired_files(const gchar *dir, guint hours) const gchar *dir_name; struct stat s; gchar *prev_dir; - gint file_no; + guint file_no; time_t mtime, now, expire_time; prev_dir = g_get_current_dir(); @@ -2641,7 +2659,7 @@ gint remove_expired_files(const gchar *dir, guint hours) expire_time = hours * 60 * 60; while ((dir_name = g_dir_read_name(dp)) != NULL) { - file_no = to_number(dir_name); + file_no = to_unumber(dir_name); if (file_no > 0) { if (g_stat(dir_name, &s) < 0) { FILE_OP_ERROR(dir_name, "stat"); diff --git a/libsylph/utils.h b/libsylph/utils.h index 9e5efeb0..0b624b12 100644 --- a/libsylph/utils.h +++ b/libsylph/utils.h @@ -219,6 +219,7 @@ gboolean str_case_find_equal (const gchar *haystack, /* number-string conversion */ gint to_number (const gchar *nstr); +guint to_unumber (const gchar *nstr); gchar *itos_buf (gchar *nstr, gint n); gchar *itos (gint n); |