kernel32: Avoid returning the same name when GetTempFileName is called twice in a short interval.

This commit is contained in:
Alexandre Julliard 2010-06-24 11:01:56 +02:00
parent 7649c75b40
commit 9f7bc109d2
1 changed files with 4 additions and 0 deletions

View File

@ -684,7 +684,10 @@ UINT WINAPI GetTempFileNameW( LPCWSTR path, LPCWSTR prefix, UINT unique, LPWSTR
/* get a "random" unique number and try to create the file */
HANDLE handle;
UINT num = GetTickCount() & 0xffff;
static UINT last;
/* avoid using the same name twice in a short interval */
if (last - num < 10) num = last + 1;
if (!num) num = 1;
unique = num;
do
@ -696,6 +699,7 @@ UINT WINAPI GetTempFileNameW( LPCWSTR path, LPCWSTR prefix, UINT unique, LPWSTR
{ /* We created it */
TRACE("created %s\n", debugstr_w(buffer) );
CloseHandle( handle );
last = unique;
break;
}
if (GetLastError() != ERROR_FILE_EXISTS &&