mutt_expand_file_fmt -> m_quotefile_fmt in file.c
[apps/madmutt.git] / lib-lib / file.c
index de3c75b..aee3580 100644 (file)
@@ -200,7 +200,7 @@ void mutt_unlink(const char *s)
                 fwrite(buf, 1, MIN(ssizeof(buf), sb.st_size), f);
                 sb.st_size -= MIN(ssizeof(buf), sb.st_size);
             }
-            fclose (f);
+            m_fclose(&f);
         }
     }
 }
@@ -232,16 +232,6 @@ FILE *safe_fopen(const char *path, const char *mode)
     return fopen(path, mode);
 }
 
-int safe_fclose(FILE **f)
-{
-    int r = 0;
-
-    if (*f)
-        r = fclose (*f);
-    *f = NULL;
-    return r;
-}
-
 /* If rfc1524_expand_command() is used on a recv'd message, then
  * the filename doesn't exist yet, but if its used while sending a message,
  * then we need to rename the existing file.
@@ -268,13 +258,13 @@ int mutt_rename_file(char *oldfile, char *newfile)
 
     nfp = safe_fopen(newfile, "w");
     if (!nfp) {
-        fclose (ofp);
+        m_fclose(&ofp);
         return 3;
     }
 
     mutt_copy_stream(ofp, nfp);
-    fclose(nfp);
-    fclose(ofp);
+    m_fclose(&nfp);
+    m_fclose(&ofp);
     mutt_unlink(oldfile);
     return 0;
 }
@@ -465,6 +455,14 @@ ssize_t m_file_fmt(char *dst, ssize_t n, const char *fmt, const char *src)
     return pos;
 }
 
+ssize_t
+m_quotefile_fmt(char *dst, ssize_t n, const char *fmt, const char *src)
+{
+    char tmp[LONG_STRING];
+    mutt_quote_filename(tmp, sizeof(tmp), src);
+    return m_file_fmt(dst, n, fmt, tmp);
+}
+
 static ssize_t
 m_tempftplize(char *dst, ssize_t dlen, const char *fmt, const char *s)
 {