Fix performance loss on certain file I/O that doesn't need
[claws.git] / src / common / file-utils.c
index 765f3ef60b3d18f1e4473abc95f84217cabb9317..8f58fece8dc48f259d1e36fa1d79f7475ab7e30f 100644 (file)
@@ -511,10 +511,11 @@ gint canonicalize_file_replace(const gchar *file)
 }
 
 
-gint str_write_to_file(const gchar *str, const gchar *file)
+gint str_write_to_file(const gchar *str, const gchar *file, gboolean safe)
 {
        FILE *fp;
        size_t len;
+       int r;
 
        cm_return_val_if_fail(str != NULL, -1);
        cm_return_val_if_fail(file != NULL, -1);
@@ -537,7 +538,13 @@ gint str_write_to_file(const gchar *str, const gchar *file)
                return -1;
        }
 
-       if (claws_safe_fclose(fp) == EOF) {
+       if (safe) {
+               r = claws_safe_fclose(fp);
+       } else {
+               r = claws_fclose(fp);
+       }
+
+       if (r == EOF) {
                FILE_OP_ERROR(file, "claws_fclose");
                claws_unlink(file);
                return -1;