diff options
author | dkf <donal.k.fellows@manchester.ac.uk> | 2012-11-14 14:29:29 (GMT) |
---|---|---|
committer | dkf <donal.k.fellows@manchester.ac.uk> | 2012-11-14 14:29:29 (GMT) |
commit | c1dd40e848612804dfe4d18f1f687acae3b7b2a6 (patch) | |
tree | 05b1f19e29b491de907eac0275afc0009a0f8cc2 | |
parent | e82b21ebc983b5f43ad7a4e9d0d90c47e2cbe73b (diff) | |
download | tcl-c1dd40e848612804dfe4d18f1f687acae3b7b2a6.zip tcl-c1dd40e848612804dfe4d18f1f687acae3b7b2a6.tar.gz tcl-c1dd40e848612804dfe4d18f1f687acae3b7b2a6.tar.bz2 |
Backport from Tcl 8.6.
* unix/tclUnixPipe.c (DefaultTempDir): [Bug 2933003]: Allow overriding
of the back-stop default temporary file location at compile time by
setting the TCL_TEMPORARY_FILE_DIRECTORY #def to a string containing
the directory name (defaults to "/tmp" as that is the most common
default).
-rw-r--r-- | ChangeLog | 8 | ||||
-rw-r--r-- | unix/tclUnixPipe.c | 42 |
2 files changed, 48 insertions, 2 deletions
@@ -1,3 +1,11 @@ +2012-11-14 Donal K. Fellows <dkf@users.sf.net> + + * unix/tclUnixPipe.c (DefaultTempDir): [Bug 2933003]: Allow overriding + of the back-stop default temporary file location at compile time by + setting the TCL_TEMPORARY_FILE_DIRECTORY #def to a string containing + the directory name (defaults to "/tmp" as that is the most common + default). + 2012-11-07 Don Porter <dgp@users.sourceforge.net> * win/tclWinSock.c: [Bug 3574493] Avoid hanging on exit due to diff --git a/unix/tclUnixPipe.c b/unix/tclUnixPipe.c index 829a4a6..4540ae6 100644 --- a/unix/tclUnixPipe.c +++ b/unix/tclUnixPipe.c @@ -199,7 +199,7 @@ TclpCreateTempFile(contents) * We should also check against making more then TMP_MAX of these. */ - strcpy(fileName, P_tmpdir); /* INTL: Native. */ + strcpy(fileName, DefaultTempDir()); /* INTL: Native. */ if (fileName[strlen(fileName) - 1] != '/') { strcat(fileName, "/"); /* INTL: Native. */ } @@ -251,7 +251,7 @@ TclpTempFileName() * We should also check against making more then TMP_MAX of these. */ - strcpy(fileName, P_tmpdir); /* INTL: Native. */ + strcpy(fileName, DefaultTempDir()); /* INTL: Native. */ if (fileName[strlen(fileName) - 1] != '/') { strcat(fileName, "/"); /* INTL: Native. */ } @@ -271,6 +271,44 @@ TclpTempFileName() /* *---------------------------------------------------------------------- * + * DefaultTempDir -- + * + * Helper that does *part* of what tempnam() does. + * + *---------------------------------------------------------------------- + */ + +static const char * +DefaultTempDir(void) +{ + const char *dir; + struct stat buf; + + dir = getenv("TMPDIR"); + if (dir && dir[0] && stat(dir, &buf) == 0 && S_ISDIR(buf.st_mode) + && access(dir, W_OK)) { + return dir; + } + +#ifdef P_tmpdir + dir = P_tmpdir; + if (stat(dir, &buf) == 0 && S_ISDIR(buf.st_mode) && access(dir, W_OK)) { + return dir; + } +#endif + + /* + * Assume that the default location ("/tmp" if not overridden) is always + * an existing writable directory; we've no recovery mechanism if it + * isn't. + */ + + return TCL_TEMPORARY_FILE_DIRECTORY; +} + +/* + *---------------------------------------------------------------------- + * * TclpCreatePipe -- * * Creates a pipe - simply calls the pipe() function. |