more sync with sylpheed 0.5.0pre1
[claws.git] / src / utils.c
index e30a5b0e308b37f20bb88bc1ce8f62339bb09432..f5b720074af51db56da560a3eb0765d6652f254e 100644 (file)
@@ -190,6 +190,21 @@ gchar *strretchomp(gchar *str)
        return str;
 }
 
+/* remove trailing character */
+gchar *strtailchomp(gchar *str, gchar tail_char)
+{
+       register gchar *s;
+
+       if (!*str) return str;
+       if (tail_char == '\0') return str;
+
+       for (s = str + strlen(str) - 1; s >= str && *s == tail_char; s--)
+               *s = '\0';
+
+       return str;
+}
+
+
 /* Similar to `strstr' but this function ignores the case of both strings.  */
 gchar *strcasestr(const gchar *haystack, const gchar *needle)
 {
@@ -1362,11 +1377,12 @@ gint remove_all_files(const gchar *dir)
        return 0;
 }
 
-gint remove_all_numbered_files(const gchar *dir)
+gint remove_numbered_files(const gchar *dir, gint first, gint last)
 {
        DIR *dp;
        struct dirent *d;
        gchar *prev_dir;
+       gint fileno;
 
        prev_dir = g_get_current_dir();
 
@@ -1381,10 +1397,12 @@ gint remove_all_numbered_files(const gchar *dir)
        }
 
        while ((d = readdir(dp)) != NULL) {
-               if (to_number(d->d_name) < 0) continue;
-
-               if (unlink(d->d_name) < 0)
-                       FILE_OP_ERROR(d->d_name, "unlink");
+               fileno = to_number(d->d_name);
+               if (fileno >= 0 && first <= fileno &&
+                   (last < 0 || fileno <= last)) {
+                       if (unlink(d->d_name) < 0)
+                               FILE_OP_ERROR(d->d_name, "unlink");
+               }
        }
 
        closedir(dp);
@@ -1400,6 +1418,11 @@ gint remove_all_numbered_files(const gchar *dir)
        return 0;
 }
 
+gint remove_all_numbered_files(const gchar *dir)
+{
+       return remove_numbered_files(dir, 0, -1);
+}
+
 gint remove_dir_recursive(const gchar *dir)
 {
        struct stat s;