kernel32: Avoid returning the same name when GetTempFileName is called twice in a short interval.
This commit is contained in:
parent
7649c75b40
commit
9f7bc109d2
@ -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 */
|
/* get a "random" unique number and try to create the file */
|
||||||
HANDLE handle;
|
HANDLE handle;
|
||||||
UINT num = GetTickCount() & 0xffff;
|
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;
|
if (!num) num = 1;
|
||||||
unique = num;
|
unique = num;
|
||||||
do
|
do
|
||||||
@ -696,6 +699,7 @@ UINT WINAPI GetTempFileNameW( LPCWSTR path, LPCWSTR prefix, UINT unique, LPWSTR
|
|||||||
{ /* We created it */
|
{ /* We created it */
|
||||||
TRACE("created %s\n", debugstr_w(buffer) );
|
TRACE("created %s\n", debugstr_w(buffer) );
|
||||||
CloseHandle( handle );
|
CloseHandle( handle );
|
||||||
|
last = unique;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (GetLastError() != ERROR_FILE_EXISTS &&
|
if (GetLastError() != ERROR_FILE_EXISTS &&
|
||||||
|
Loading…
x
Reference in New Issue
Block a user