MSVCRT: _tempnam not following documentation
Phil Lodwick
Phil.Lodwick at EFI.COM
Tue Nov 8 15:56:24 CST 2005
When working on a problem with _tempnam(".", NULL) failing, I saw that
_tempnam
was not following the documented rules. In particular:
_tempnam will generate a unique file name for a directory chosen by the
following rules:
- If the TMP environment variable is defined and set to a valid directory
name,
unique file names will be generated for the directory specified by TMP.
- If the TMP environment variable is not defined or if it is set to the name
of a directory that does not exist, _tempnam will use the dir parameter as
the path for which it will generate unique names.
- If the TMP environment variable is not defined or if it is set to the name
of a directory that does not exist, and if dir is either NULL or set to
the
name of a directory that does not exist, _tempnam will use the current
working
directory to generate unique names. Currently, if both TMP and dir specify
names
of directories that do not exist, the _tempnam function call will fail.
This patch should implement these rules.
James Hawkins pointed out in my previous patch that I should write
conformance tests
And submit those as well. I have a question for this case that I will ask on
wine-devel.
Phil
----
ChangeLog:
_tempnam uses the TMP environment variable
Index: dlls/msvcrt/file.c
===================================================================
RCS file: /home/wine/wine/dlls/msvcrt/file.c,v
retrieving revision 1.91
diff -u -r1.91 file.c
--- dlls/msvcrt/file.c 7 Oct 2005 15:01:15 -0000 1.91
+++ dlls/msvcrt/file.c 8 Nov 2005 21:40:37 -0000
@@ -1887,9 +1887,34 @@
char *_tempnam(const char *dir, const char *prefix)
{
char tmpbuf[MAX_PATH];
+ char tmpdir[MAX_PATH];
+ BOOL HaveEnvVar;
TRACE("dir (%s) prefix (%s)\n",dir,prefix);
- if (GetTempFileNameA(dir,prefix,0,tmpbuf))
+ HaveEnvVar = (GetEnvironmentVariableA("TMP", tmpdir, MAX_PATH) != 0);
+ if (!HaveEnvVar || _access(tmpdir, 0) != 0)
+ {
+ BOOL UseCurrentWorkingDir = FALSE;
+
+ if (dir)
+ {
+ lstrcpynA(tmpdir, dir, MAX_PATH);
+ if (_access(tmpdir, 0) != 0)
+ {
+ if (!HaveEnvVar)
+ return NULL;
+ UseCurrentWorkingDir = TRUE;
+ }
+ }
+ else
+ UseCurrentWorkingDir = TRUE;
+
+ if (UseCurrentWorkingDir)
+ if (GetCurrentDirectoryA(MAX_PATH, tmpdir) < 1)
+ return NULL;
+ }
+
+ if (GetTempFileNameA(tmpdir,prefix,0,tmpbuf))
{
TRACE("got name (%s)\n",tmpbuf);
DeleteFileA(tmpbuf);
More information about the wine-patches
mailing list