1
0
Fork 0
mirror of git://git.code.sf.net/p/zsh/code synced 2025-10-31 06:00:54 +01:00

Made gettempname() take a prefix arg and a use_heap arg. When prefix is

non-NULL, it uses the specified prefix instead of $TMPPREFIX.
This commit is contained in:
Wayne Davison 2004-10-18 19:07:46 +00:00
parent 945a40f7e6
commit 1637c4eba6

View file

@ -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();