]> granicus.if.org Git - neomutt/commitdiff
Refactor several callers of mutt_mktemp() to mutt_file_mkstemp()
authorWill Curry <will@robotican.org>
Wed, 18 Apr 2018 03:32:04 +0000 (22:32 -0500)
committerRichard Russon <rich@flatcap.org>
Sat, 21 Apr 2018 12:19:45 +0000 (13:19 +0100)
nntp.c
pattern.c
pop.c

diff --git a/nntp.c b/nntp.c
index 24085856bd28a72a61a80c978168afa73621b2bb..edd677e794fa509b9ac276cc067947a2d0c46f10 100644 (file)
--- a/nntp.c
+++ b/nntp.c
@@ -1110,8 +1110,6 @@ static int parse_overview_line(char *line, void *data)
   struct Context *ctx = fc->ctx;
   struct NntpData *nntp_data = ctx->data;
   struct Header *hdr = NULL;
-  FILE *fp = NULL;
-  char tempfile[_POSIX_PATH_MAX];
   char *header = NULL, *field = NULL;
   bool save = true;
   anum_t anum;
@@ -1141,8 +1139,7 @@ static int parse_overview_line(char *line, void *data)
   }
 
   /* convert overview line to header */
-  mutt_mktemp(tempfile, sizeof(tempfile));
-  fp = mutt_file_fopen(tempfile, "w+");
+  FILE *fp = mutt_file_mkstemp();
   if (!fp)
     return -1;
 
@@ -1156,7 +1153,6 @@ static int parse_overview_line(char *line, void *data)
       if (strstr(header, ":full") == NULL && fputs(header, fp) == EOF)
       {
         mutt_file_fclose(&fp);
-        unlink(tempfile);
         return -1;
       }
       header = strchr(header, '\0') + 1;
@@ -1168,7 +1164,6 @@ static int parse_overview_line(char *line, void *data)
     if (fputs(b, fp) == EOF || fputc('\n', fp) == EOF)
     {
       mutt_file_fclose(&fp);
-      unlink(tempfile);
       return -1;
     }
   }
@@ -1184,7 +1179,6 @@ static int parse_overview_line(char *line, void *data)
   hdr->env->newsgroups = mutt_str_strdup(nntp_data->group);
   hdr->received = hdr->date_sent;
   mutt_file_fclose(&fp);
-  unlink(tempfile);
 
 #ifdef USE_HCACHE
   if (fc->hc)
@@ -1397,14 +1391,10 @@ static int nntp_fetch_headers(struct Context *ctx, void *hc, anum_t first,
     /* fetch header from server */
     else
     {
-      char tempfile[_POSIX_PATH_MAX];
-
-      mutt_mktemp(tempfile, sizeof(tempfile));
-      FILE *fp = mutt_file_fopen(tempfile, "w+");
+      FILE *fp = mutt_file_mkstemp();
       if (!fp)
       {
-        mutt_perror(tempfile);
-        unlink(tempfile);
+        mutt_perror("mutt_file_mkstemp() failed!");
         rc = -1;
         break;
       }
@@ -1414,7 +1404,6 @@ static int nntp_fetch_headers(struct Context *ctx, void *hc, anum_t first,
       if (rc)
       {
         mutt_file_fclose(&fp);
-        unlink(tempfile);
         if (rc < 0)
           break;
 
@@ -1441,7 +1430,6 @@ static int nntp_fetch_headers(struct Context *ctx, void *hc, anum_t first,
       hdr->env = mutt_rfc822_read_header(fp, hdr, 0, 0);
       hdr->received = hdr->date_sent;
       mutt_file_fclose(&fp);
-      unlink(tempfile);
     }
 
     /* save header in context */
@@ -2447,15 +2435,12 @@ int nntp_check_new_groups(struct NntpServer *nserv)
 int nntp_check_msgid(struct Context *ctx, const char *msgid)
 {
   struct NntpData *nntp_data = ctx->data;
-  char tempfile[_POSIX_PATH_MAX];
   char buf[LONG_STRING];
 
-  mutt_mktemp(tempfile, sizeof(tempfile));
-  FILE *fp = mutt_file_fopen(tempfile, "w+");
+  FILE *fp = mutt_file_mkstemp();
   if (!fp)
   {
-    mutt_perror(tempfile);
-    unlink(tempfile);
+    mutt_perror("mutt_file_mkstemp() failed!");
     return -1;
   }
 
@@ -2464,7 +2449,6 @@ int nntp_check_msgid(struct Context *ctx, const char *msgid)
   if (rc)
   {
     mutt_file_fclose(&fp);
-    unlink(tempfile);
     if (rc < 0)
       return -1;
     if (mutt_str_strncmp("430", buf, 3) == 0)
@@ -2480,7 +2464,6 @@ int nntp_check_msgid(struct Context *ctx, const char *msgid)
   hdr->data = mutt_mem_calloc(1, sizeof(struct NntpHeaderData));
   hdr->env = mutt_rfc822_read_header(fp, hdr, 0, 0);
   mutt_file_fclose(&fp);
-  unlink(tempfile);
 
   /* get article number */
   if (hdr->env->xref)
index e14be590299322a36aeaa6791f3849e4a3c5dccb..eae0a27fa1597dde812f7ebcbb60e892fbcd11f0 100644 (file)
--- a/pattern.c
+++ b/pattern.c
@@ -903,7 +903,6 @@ static int msg_search(struct Context *ctx, struct Pattern *pat, int msgno)
   char *temp = NULL;
   size_t tempsize;
 #else
-  char tempfile[_POSIX_PATH_MAX];
   struct stat st;
 #endif
 
@@ -922,11 +921,10 @@ static int msg_search(struct Context *ctx, struct Pattern *pat, int msgno)
       return 0;
     }
 #else
-    mutt_mktemp(tempfile, sizeof(tempfile));
-    s.fpout = mutt_file_fopen(tempfile, "w+");
+    s.fpout = mutt_file_mkstemp();
     if (!s.fpout)
     {
-      mutt_perror(tempfile);
+      mutt_perror("mutt_file_mkstemp() failed");
       return 0;
     }
 #endif
@@ -946,8 +944,6 @@ static int msg_search(struct Context *ctx, struct Pattern *pat, int msgno)
           mutt_file_fclose(&s.fpout);
 #ifdef USE_FMEMOPEN
           FREE(&temp);
-#else
-          unlink(tempfile);
 #endif
         }
         return 0;
@@ -1036,8 +1032,6 @@ static int msg_search(struct Context *ctx, struct Pattern *pat, int msgno)
 #ifdef USE_FMEMOPEN
     if (tempsize)
       FREE(&temp);
-#else
-    unlink(tempfile);
 #endif
   }
 
diff --git a/pop.c b/pop.c
index 2951ff767bbf49d8c5e1ae68bdbd8dea8bf0bbfe..db48b2e05c61515c981468c231a9b48e8937504f 100644 (file)
--- a/pop.c
+++ b/pop.c
@@ -95,13 +95,11 @@ static int pop_read_header(struct PopData *pop_data, struct Header *h)
   int rc, index;
   size_t length;
   char buf[LONG_STRING];
-  char tempfile[_POSIX_PATH_MAX];
 
-  mutt_mktemp(tempfile, sizeof(tempfile));
-  FILE *f = mutt_file_fopen(tempfile, "w+");
+  FILE *f = mutt_file_mkstemp();
   if (!f)
   {
-    mutt_perror(tempfile);
+    mutt_perror("mutt_file_mkstemp failed!");
     return -3;
   }
 
@@ -162,7 +160,6 @@ static int pop_read_header(struct PopData *pop_data, struct Header *h)
   }
 
   mutt_file_fclose(&f);
-  unlink(tempfile);
   return rc;
 }