]> granicus.if.org Git - neomutt/commitdiff
two mutt_mktemp replacements
authorRichard Russon <rich@flatcap.org>
Thu, 12 Jul 2018 22:07:59 +0000 (23:07 +0100)
committerRichard Russon <rich@flatcap.org>
Mon, 16 Jul 2018 22:38:22 +0000 (23:38 +0100)
history.c
imap/message.c

index 09210638e3d0b19ee7254a3c3fad87b04adf919f..e494d14aaec0093c4b33b5b6884cd50563d5178b 100644 (file)
--- a/history.c
+++ b/history.c
@@ -222,8 +222,7 @@ static int dup_hash_inc(struct Hash *dup_hash, char *str)
  */
 static void shrink_histfile(void)
 {
-  char tmpfname[PATH_MAX];
-  FILE *tmp = NULL;
+  FILE *tmpfp = NULL;
   int n[HC_LAST] = { 0 };
   int line, hclass, read;
   char *linebuf = NULL, *p = NULL;
@@ -274,11 +273,10 @@ static void shrink_histfile(void)
 
   if (regen_file)
   {
-    mutt_mktemp(tmpfname, sizeof(tmpfname));
-    tmp = mutt_file_fopen(tmpfname, "w+");
-    if (!tmp)
+    tmpfp = mutt_file_mkstemp();
+    if (!tmpfp)
     {
-      mutt_perror(tmpfname);
+      mutt_perror("mutt_file_mkstemp() failed!");
       goto cleanup;
     }
     rewind(f);
@@ -300,23 +298,22 @@ static void shrink_histfile(void)
       }
       *p = '|';
       if (n[hclass]-- <= SaveHistory)
-        fprintf(tmp, "%s\n", linebuf);
+        fprintf(tmpfp, "%s\n", linebuf);
     }
   }
 
 cleanup:
   mutt_file_fclose(&f);
   FREE(&linebuf);
-  if (tmp)
+  if (tmpfp)
   {
-    if (fflush(tmp) == 0 && (f = fopen(HistoryFile, "w")) != NULL)
+    if (fflush(tmpfp) == 0 && (f = fopen(HistoryFile, "w")) != NULL)
     {
-      rewind(tmp);
-      mutt_file_copy_stream(tmp, f);
+      rewind(tmpfp);
+      mutt_file_copy_stream(tmpfp, f);
       mutt_file_fclose(&f);
     }
-    mutt_file_fclose(&tmp);
-    unlink(tmpfname);
+    mutt_file_fclose(&tmpfp);
   }
   if (HistoryRemoveDups)
     for (hclass = 0; hclass < HC_LAST; hclass++)
index 09881a04bd3f71aa70a7518d607567bd4336c315..6a2367ddd8713e2f57e44684b32d3f4cd4606289 100644 (file)
@@ -612,8 +612,6 @@ static void set_changed_flag(struct Context *ctx, struct Header *h,
 int imap_read_headers(struct ImapData *idata, unsigned int msn_begin, unsigned int msn_end)
 {
   char *hdrreq = NULL;
-  FILE *fp = NULL;
-  char tempfile[PATH_MAX];
   int msgno, idx;
   struct ImapHeader h;
   struct ImapStatus *status = NULL;
@@ -655,14 +653,12 @@ int imap_read_headers(struct ImapData *idata, unsigned int msn_begin, unsigned i
 
   /* instead of downloading all headers and then parsing them, we parse them
    * as they come in. */
-  mutt_mktemp(tempfile, sizeof(tempfile));
-  fp = mutt_file_fopen(tempfile, "w+");
+  FILE *fp = mutt_file_mkstemp();
   if (!fp)
   {
-    mutt_error(_("Could not create temporary file %s"), tempfile);
+    mutt_perror("mutt_file_mkstemp() failed!");
     goto error_out_0;
   }
-  unlink(tempfile);
 
   /* make sure context has room to hold the mailbox */
   while (msn_end > ctx->hdrmax)