From: Richard Russon Date: Thu, 12 Jul 2018 22:07:59 +0000 (+0100) Subject: two mutt_mktemp replacements X-Git-Tag: 2019-10-25~757^2~2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8f6d251a927a05eef81afdd1f92515e7ffecf805;p=neomutt two mutt_mktemp replacements --- diff --git a/history.c b/history.c index 09210638e..e494d14aa 100644 --- 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++) diff --git a/imap/message.c b/imap/message.c index 09881a04b..6a2367ddd 100644 --- a/imap/message.c +++ b/imap/message.c @@ -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)