From: Kevin McCarthy Date: Mon, 15 Oct 2018 01:36:08 +0000 (-0700) Subject: Add mutt_buffer_mktemp() transition function X-Git-Tag: 2019-10-25~485^2~14 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=906dd2429d16d8bb130a16e3f02cbe02c7f3d8a0;p=neomutt Add mutt_buffer_mktemp() transition function This is self-contained and easy to translate, so instead just create an alternate implementation using struct Buffer. --- diff --git a/muttlib.c b/muttlib.c index 718765aa4..d4c15bf08 100644 --- a/muttlib.c +++ b/muttlib.c @@ -502,6 +502,28 @@ uint64_t mutt_rand64(void) return ret; } +/** + * mutt_buffer_mktemp_full - Create a temporary file + * @param buf Buffer for result + * @param prefix Prefix for filename + * @param suffix Suffix for filename + * @param src Source file of caller + * @param line Source line number of caller + */ +void mutt_buffer_mktemp_full(struct Buffer *buf, const char *prefix, + const char *suffix, const char *src, int line) +{ + mutt_buffer_printf(buf, "%s/%s-%s-%d-%d-%ld%ld%s%s", NONULL(Tmpdir), NONULL(prefix), + NONULL(Hostname), (int) getuid(), (int) getpid(), random(), + random(), suffix ? "." : "", NONULL(suffix)); + mutt_debug(3, "%s:%d: mutt_mktemp returns \"%s\".\n", src, line, mutt_b2s(buf)); + if (unlink(mutt_b2s(buf)) && errno != ENOENT) + { + mutt_debug(1, "%s:%d: ERROR: unlink(\"%s\"): %s (errno %d)\n", src, line, + mutt_b2s(buf), strerror(errno), errno); + } +} + /** * mutt_mktemp_full - Create a temporary filename * @param buf Buffer for result diff --git a/muttlib.h b/muttlib.h index df2b1a393..39f13c7d8 100644 --- a/muttlib.h +++ b/muttlib.h @@ -42,6 +42,7 @@ extern struct Regex *GecosMask; #define MUTT_RANDTAG_LEN 16 void mutt_adv_mktemp(char *s, size_t l); +void mutt_buffer_mktemp_full(struct Buffer *buf, const char *prefix, const char *suffix, const char *src, int line); int mutt_check_overwrite(const char *attname, const char *path, char *fname, size_t flen, int *append, char **directory); void mutt_encode_path(char *dest, size_t dlen, const char *src); void mutt_expando_format(char *buf, size_t buflen, size_t col, int cols, const char *src, format_t *callback, unsigned long data, enum FormatFlag flags); @@ -69,4 +70,7 @@ void mutt_sleep(short s); #define mutt_mktemp(a, b) mutt_mktemp_pfx_sfx(a, b, "neomutt", NULL) #define mutt_mktemp_pfx_sfx(a, b, c, d) mutt_mktemp_full(a, b, c, d, __FILE__, __LINE__) +#define mutt_buffer_mktemp(a) mutt_buffer_mktemp_pfx_sfx(a, "neomutt", NULL) +#define mutt_buffer_mktemp_pfx_sfx(a, b, c) mutt_buffer_mktemp_full(a, b, c, __FILE__, __LINE__) + #endif /* MUTT_MUTTLIB_H */