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 /libsylph/utils.c | |
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
Diffstat (limited to 'libsylph/utils.c')
-rw-r--r-- | libsylph/utils.c | 26 |
1 files changed, 22 insertions, 4 deletions
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"); |