diff options
author | Wayne Davison <wayned@users.sourceforge.net> | 2004-10-18 19:07:46 +0000 |
---|---|---|
committer | Wayne Davison <wayned@users.sourceforge.net> | 2004-10-18 19:07:46 +0000 |
commit | 1637c4eba690a60cd90dde0d81a3b1ebb0dac68b (patch) | |
tree | f0662b9229268b065b5eb91f1c44792363bf4578 /Src/utils.c | |
parent | 945a40f7e69dcbd194a2a45889512c8849dce2c9 (diff) | |
download | zsh-1637c4eba690a60cd90dde0d81a3b1ebb0dac68b.tar.gz zsh-1637c4eba690a60cd90dde0d81a3b1ebb0dac68b.tar.xz zsh-1637c4eba690a60cd90dde0d81a3b1ebb0dac68b.zip |
Made gettempname() take a prefix arg and a use_heap arg. When prefix is
non-NULL, it uses the specified prefix instead of $TMPPREFIX.
Diffstat (limited to 'Src/utils.c')
-rw-r--r-- | Src/utils.c | 24 |
1 files changed, 15 insertions, 9 deletions
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(); |