From: Kevin McCarthy Date: Mon, 15 Oct 2018 02:02:47 +0000 (-0700) Subject: Add mutt_buffer_adv_mktemp() transition function. X-Git-Tag: mutt-1-11-rel~34 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=57caae48aac7f3428df58a3754aa990841e6fc96;p=mutt Add mutt_buffer_adv_mktemp() transition function. --- diff --git a/muttlib.c b/muttlib.c index 5a76a9ed..7789479c 100644 --- a/muttlib.c +++ b/muttlib.c @@ -55,6 +55,36 @@ BODY *mutt_new_body (void) return (p); } +void mutt_buffer_adv_mktemp (BUFFER *buf) +{ + BUFFER *prefix = NULL; + char *suffix; + struct stat sb; + + if (!(buf->data && buf->data[0])) + { + mutt_buffer_mktemp (buf); + } + else + { + prefix = mutt_buffer_pool_get (); + mutt_buffer_strcpy (prefix, buf->data); + mutt_sanitize_filename (prefix->data, 1); + mutt_buffer_printf (buf, "%s/%s", NONULL (Tempdir), mutt_b2s (prefix)); + if (lstat (mutt_b2s (buf), &sb) == -1 && errno == ENOENT) + goto out; + + if ((suffix = strrchr (prefix->data, '.')) != NULL) + { + *suffix = 0; + ++suffix; + } + mutt_buffer_mktemp_pfx_sfx (buf, mutt_b2s (prefix), suffix); + +out: + mutt_buffer_pool_release (&prefix); + } +} /* Modified by blong to accept a "suggestion" for file name. If * that file exists, then construct one with unique name but diff --git a/protos.h b/protos.h index 074a6813..19100d6c 100644 --- a/protos.h +++ b/protos.h @@ -159,6 +159,7 @@ REGEXP *mutt_compile_regexp (const char *, int); void mutt_account_hook (const char* url); void mutt_add_to_reference_headers (ENVELOPE *env, ENVELOPE *curenv, LIST ***pp, LIST ***qq); +void mutt_buffer_adv_mktemp (BUFFER *); void mutt_adv_mktemp (char *, size_t); void mutt_alias_menu (char *, size_t, ALIAS *); void mutt_allow_interrupt (int);