From 1637c4eba690a60cd90dde0d81a3b1ebb0dac68b Mon Sep 17 00:00:00 2001 From: Wayne Davison Date: Mon, 18 Oct 2004 19:07:46 +0000 Subject: Made gettempname() take a prefix arg and a use_heap arg. When prefix is non-NULL, it uses the specified prefix instead of $TMPPREFIX. --- Src/utils.c | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) (limited to 'Src') diff --git a/Src/utils.c b/Src/utils.c index f07cd7811..31e9c2b26 100644 --- a/Src/utils.c +++ b/Src/utils.c @@ -1122,28 +1122,34 @@ zclose(int fd) return -1; } -/* Get a file name relative to $TMPPREFIX which * - * is unique, for use as a temporary file. */ - #ifdef HAVE__MKTEMP extern char *_mktemp(char *); #endif +/* Get a unique filename for use as a temporary file. If "prefix" is + * NULL, the name is relative to $TMPPREFIX; If it is non-NULL, the + * unique suffix includes a prefixed '.' for improved readability. If + * "use_heap" is true, we allocate the returned name on the heap. */ + /**/ mod_export char * -gettempname(void) +gettempname(const char *prefix, int use_heap) { - char *s, *ret; + char *ret, *suffix = prefix ? ".XXXXXX" : "XXXXXX"; queue_signals(); - if (!(s = getsparam("TMPPREFIX"))) - s = DEFAULT_TMPPREFIX; + if (!prefix && !(prefix = getsparam("TMPPREFIX"))) + prefix = DEFAULT_TMPPREFIX; + if (use_heap) + ret = dyncat(unmeta(prefix), suffix); + else + ret = bicat(unmeta(prefix), suffix); #ifdef HAVE__MKTEMP /* Zsh uses mktemp() safely, so silence the warnings */ - ret = ((char *) _mktemp(dyncat(unmeta(s), "XXXXXX"))); + ret = (char *) _mktemp(ret); #else - ret = ((char *) mktemp(dyncat(unmeta(s), "XXXXXX"))); + ret = (char *) mktemp(ret); #endif unqueue_signals(); -- cgit 1.4.1