Wrap file I/O to claws_* to benefit from custom locking when
[claws.git] / src / matcher.c
index 5b67051c4c6e29f6c2854801842088bc410f57d3..c87c89747d0a1509b295b6af4378552beac21ce1 100644 (file)
@@ -49,6 +49,7 @@
 #include "tags.h"
 #include "folder_item_prefs.h"
 #include "procmsg.h"
+#include "claws_io.h"
 
 /*!
  *\brief       Keyword lookup element
@@ -1623,7 +1624,7 @@ static gboolean matcherlist_match_binary_content(MatcherList *matchers, MimeInfo
        if (!outfp)
                return FALSE;
 
-       while (fgets(buf, sizeof(buf), outfp) != NULL) {
+       while (claws_fgets(buf, sizeof(buf), outfp) != NULL) {
                strretchomp(buf);
 
                for (l = matchers->matchers ; l != NULL ; l = g_slist_next(l)) {
@@ -1664,14 +1665,14 @@ static gboolean matcherlist_match_binary_content(MatcherList *matchers, MimeInfo
                         * no need to check the others. */
                        if (matcher->result && matcher->done) {
                                if (!matchers->bool_and) {
-                                       fclose(outfp);
+                                       claws_fclose(outfp);
                                        return TRUE;
                                }
                        }
                }
        }
 
-       fclose(outfp);
+       claws_fclose(outfp);
        return FALSE;
 }
 
@@ -1823,8 +1824,8 @@ static gboolean matcherlist_match_file(MatcherList *matchers, MsgInfo *info,
        if (file == NULL)
                return FALSE;
 
-       if ((fp = g_fopen(file, "rb")) == NULL) {
-               FILE_OP_ERROR(file, "fopen");
+       if ((fp = claws_fopen(file, "rb")) == NULL) {
+               FILE_OP_ERROR(file, "claws_fopen");
                g_free(file);
                return result;
        }
@@ -1866,7 +1867,7 @@ static gboolean matcherlist_match_file(MatcherList *matchers, MsgInfo *info,
 
        g_free(file);
 
-       fclose(fp);
+       claws_fclose(fp);
        
        return result;
 }
@@ -2429,42 +2430,42 @@ static int prefs_filtering_write(FILE *fp, GSList *prefs_filtering)
                        continue;
 
                if (prop->enabled) {
-                       if (fputs("enabled ", fp) == EOF) {
-                               FILE_OP_ERROR("filtering config", "fputs");
+                       if (claws_fputs("enabled ", fp) == EOF) {
+                               FILE_OP_ERROR("filtering config", "claws_fputs");
                                return -1;
                        }
                } else {
-                       if (fputs("disabled ", fp) == EOF) {
-                               FILE_OP_ERROR("filtering config", "fputs");
+                       if (claws_fputs("disabled ", fp) == EOF) {
+                               FILE_OP_ERROR("filtering config", "claws_fputs");
                                return -1;
                        }
                }
 
-               if (fputs("rulename \"", fp) == EOF) {
-                       FILE_OP_ERROR("filtering config", "fputs");
+               if (claws_fputs("rulename \"", fp) == EOF) {
+                       FILE_OP_ERROR("filtering config", "claws_fputs");
                        g_free(filtering_str);
                        return -1;
                }
                tmp_name = prop->name;
                while (tmp_name && *tmp_name != '\0') {
                        if (*tmp_name != '"') {
-                               if (fputc(*tmp_name, fp) == EOF) {
-                                       FILE_OP_ERROR("filtering config", "fputs || fputc");
+                               if (claws_fputc(*tmp_name, fp) == EOF) {
+                                       FILE_OP_ERROR("filtering config", "claws_fputs || claws_fputc");
                                        g_free(filtering_str);
                                        return -1;
                                }
                        } else if (*tmp_name == '"') {
-                               if (fputc('\\', fp) == EOF ||
-                                   fputc('"', fp) == EOF) {
-                                       FILE_OP_ERROR("filtering config", "fputs || fputc");
+                               if (claws_fputc('\\', fp) == EOF ||
+                                   claws_fputc('"', fp) == EOF) {
+                                       FILE_OP_ERROR("filtering config", "claws_fputs || claws_fputc");
                                        g_free(filtering_str);
                                        return -1;
                                }
                        }
                        tmp_name ++;
                }
-               if (fputs("\" ", fp) == EOF) {
-                       FILE_OP_ERROR("filtering config", "fputs");
+               if (claws_fputs("\" ", fp) == EOF) {
+                       FILE_OP_ERROR("filtering config", "claws_fputs");
                        g_free(filtering_str);
                        return -1;
                }
@@ -2473,17 +2474,17 @@ static int prefs_filtering_write(FILE *fp, GSList *prefs_filtering)
                        gchar *tmp = NULL;
 
                        tmp = g_strdup_printf("account %d ", prop->account_id);
-                       if (fputs(tmp, fp) == EOF) {
-                               FILE_OP_ERROR("filtering config", "fputs");
+                       if (claws_fputs(tmp, fp) == EOF) {
+                               FILE_OP_ERROR("filtering config", "claws_fputs");
                                g_free(tmp);
                                return -1;
                        }
                        g_free(tmp);
                }
 
-               if(fputs(filtering_str, fp) == EOF ||
-                   fputc('\n', fp) == EOF) {
-                       FILE_OP_ERROR("filtering config", "fputs || fputc");
+               if(claws_fputs(filtering_str, fp) == EOF ||
+                   claws_fputc('\n', fp) == EOF) {
+                       FILE_OP_ERROR("filtering config", "claws_fputs || claws_fputc");
                        g_free(filtering_str);
                        return -1;
                }
@@ -2531,7 +2532,7 @@ static gboolean prefs_matcher_write_func(GNode *node, gpointer d)
                        data->error = TRUE;
                        goto fail;
                }
-               if (fputc('\n', data->fp) == EOF) {
+               if (claws_fputc('\n', data->fp) == EOF) {
                        data->error = TRUE;
                        goto fail;
                }
@@ -2569,19 +2570,19 @@ static int prefs_matcher_save(FILE *fp)
         /* pre global rules */
         if (fprintf(fp, "[preglobal]\n") < 0 ||
             prefs_filtering_write(fp, pre_global_processing) < 0 ||
-            fputc('\n', fp) == EOF)
+            claws_fputc('\n', fp) == EOF)
                return -1;
 
         /* post global rules */
         if (fprintf(fp, "[postglobal]\n") < 0 ||
             prefs_filtering_write(fp, post_global_processing) < 0 ||
-            fputc('\n', fp) == EOF)
+            claws_fputc('\n', fp) == EOF)
                return -1;
         
         /* filtering rules */
        if (fprintf(fp, "[filtering]\n") < 0 ||
             prefs_filtering_write(fp, filtering_rules) < 0 ||
-            fputc('\n', fp) == EOF)
+            claws_fputc('\n', fp) == EOF)
                return -1;
 
        return 0;
@@ -2629,11 +2630,11 @@ void prefs_matcher_read_config(void)
 
        rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, MATCHER_RC, NULL);
 
-       f = g_fopen(rcpath, "rb");
+       f = claws_fopen(rcpath, "rb");
        g_free(rcpath);
 
        if (f != NULL) {
                matcher_parser_start_parsing(f);
-               fclose(matcher_parserin);
+               claws_fclose(matcher_parserin);
        }
 }