Update of /cvsroot/aolserver/aolserver/nsd
In directory sc8-pr-cvs11.sourceforge.net:/tmp/cvs-serv5697
Modified Files:
tclfile.c
Log Message:
Fix ns_tmpnam for WIN32 environments to return a path in the TMP directory.
Index: tclfile.c
===================================================================
RCS file: /cvsroot/aolserver/aolserver/nsd/tclfile.c,v
retrieving revision 1.25
retrieving revision 1.26
diff -C2 -d -r1.25 -r1.26
*** tclfile.c 17 Aug 2006 19:45:37 -0000 1.25
--- tclfile.c 24 Apr 2008 07:13:40 -0000 1.26
***************
*** 569,572 ****
--- 569,606 ----
NsTclTmpNamObjCmd(ClientData arg, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[])
{
+ #ifdef WIN32
+ /*
+ The WIN32 implmentation of tmpnam() ignores the environment
+ variable TMP and generates filenames for the root
+ directory. Unfortunately, new WIN versions (Vista) don't allow
+ this. The suggested replacement is _tempnam().
+
+ The first argument of _tempnam() is the default directory, in case
+ the environment variable TMP is not set or points to a directory
+ that does not exist.
+ */
+ char *buf = _tempnam("/tmp", NULL);
+
+ if (buf == NULL) {
+ Tcl_SetResult(interp, "could not generate temporary filename.", TCL_STATIC);
+ return TCL_ERROR;
+ }
+ /*
+ Change back-slash characters into slash characters, as all other
+ paths are slash separated. Even some programs under Windows
+ do not allow back-slahed paths (e.g. Oracle's SqlLdr).
+ */
+ for (i = 0; i < strlen(buf); i++) {
+ if (buf[i] == '\\') buf[i] = '/';
+ }
+ /*
+ The documentation says that _tempnam() allocates memory via
+ malloc(); to be sure, that the "right" free() is used, we do
+ not use TCL_DYNAMIC but the TCL_VOLATILE followed by the manual
+ free().
+ */
+ Tcl_SetResult(interp, buf, TCL_VOLATILE);
+ free(buf);
+ #else
char buf[L_tmpnam];
***************
*** 576,579 ****
--- 610,614 ----
}
Tcl_SetResult(interp, buf, TCL_VOLATILE);
+ #endif
return TCL_OK;
}
|