diff options
author | dkf <donal.k.fellows@manchester.ac.uk> | 2012-11-20 12:14:18 (GMT) |
---|---|---|
committer | dkf <donal.k.fellows@manchester.ac.uk> | 2012-11-20 12:14:18 (GMT) |
commit | 0d9c3c6fea70ee5c02ec0c52388a1914bca1ff4c (patch) | |
tree | 952243458095cfc9400e26863f34f2177d5e7d62 /unix/tclUnixPipe.c | |
parent | da8e7d4661b94a3128d7ec74ba87a13d6e11ec8b (diff) | |
parent | 6ba5327e8579861a348ee361e3aff04356086458 (diff) | |
download | tcl-0d9c3c6fea70ee5c02ec0c52388a1914bca1ff4c.zip tcl-0d9c3c6fea70ee5c02ec0c52388a1914bca1ff4c.tar.gz tcl-0d9c3c6fea70ee5c02ec0c52388a1914bca1ff4c.tar.bz2 |
merge dkf-compile-misc-info
Diffstat (limited to 'unix/tclUnixPipe.c')
-rw-r--r-- | unix/tclUnixPipe.c | 43 |
1 files changed, 11 insertions, 32 deletions
diff --git a/unix/tclUnixPipe.c b/unix/tclUnixPipe.c index 654c9d8..9c21b28 100644 --- a/unix/tclUnixPipe.c +++ b/unix/tclUnixPipe.c @@ -188,28 +188,16 @@ TclFile TclpCreateTempFile( const char *contents) /* String to write into temp file, or NULL. */ { - char fileName[L_tmpnam + 9]; - const char *native; - Tcl_DString dstring; - int fd; + int fd = TclUnixOpenTemporaryFile(NULL, NULL, NULL, NULL); - /* - * We should also check against making more then TMP_MAX of these. - */ - - strcpy(fileName, P_tmpdir); /* INTL: Native. */ - if (fileName[strlen(fileName) - 1] != '/') { - strcat(fileName, "/"); /* INTL: Native. */ - } - strcat(fileName, "tclXXXXXX"); - fd = mkstemp(fileName); /* INTL: Native. */ if (fd == -1) { return NULL; } fcntl(fd, F_SETFD, FD_CLOEXEC); - unlink(fileName); /* INTL: Native. */ - if (contents != NULL) { + Tcl_DString dstring; + char *native; + native = Tcl_UtfToExternalDString(NULL, contents, -1, &dstring); if (write(fd, native, Tcl_DStringLength(&dstring)) == -1) { close(fd); @@ -241,29 +229,20 @@ TclpCreateTempFile( Tcl_Obj * TclpTempFileName(void) { - char fileName[L_tmpnam + 9]; - Tcl_Obj *result = NULL; + Tcl_Obj *nameObj = Tcl_NewObj(); int fd; - /* - * We should also check against making more then TMP_MAX of these. - */ - - strcpy(fileName, P_tmpdir); /* INTL: Native. */ - if (fileName[strlen(fileName) - 1] != '/') { - strcat(fileName, "/"); /* INTL: Native. */ - } - strcat(fileName, "tclXXXXXX"); - fd = mkstemp(fileName); /* INTL: Native. */ + Tcl_IncrRefCount(nameObj); + fd = TclUnixOpenTemporaryFile(NULL, NULL, NULL, nameObj); if (fd == -1) { + Tcl_DecrRefCount(nameObj); return NULL; } - fcntl(fd, F_SETFD, FD_CLOEXEC); - unlink(fileName); /* INTL: Native. */ - result = TclpNativeToNormalized(fileName); + fcntl(fd, F_SETFD, FD_CLOEXEC); + TclpObjDeleteFile(nameObj); close(fd); - return result; + return nameObj; } /* |