diff --git a/dlls/kernel/tests/file.c b/dlls/kernel/tests/file.c index dd1e06ca595..ee4b10b60c6 100644 --- a/dlls/kernel/tests/file.c +++ b/dlls/kernel/tests/file.c @@ -618,6 +618,23 @@ static void test_CreateFileW(void) ok(ret, "DeleteFileW: error %ld\n", GetLastError()); } + +static void test_GetTempFileNameA() { + UINT result; + char out[MAX_PATH]; + char *expected = "c:\\windows\\abc2.tmp"; + + /* this test may depend on the config file settings */ + result = GetTempFileNameA("C:", "abc", 1, out); + ok( result != 0, "GetTempFileNameA: error %ld\n", GetLastError() ); + ok( ((out[0] == 'C') && (out[1] == ':')) && (out[2] == '\\'), "GetTempFileNameA: first three characters should be C:\\, string was actually %s", out ); + + result = GetTempFileNameA("c:\\windows\\", "abc", 2, out); + ok( result != 0, "GetTempFileNameA: error %ld\n", GetLastError() ); + ok( strcasecmp( out, expected ) == 0, "GetTempFileNameA: Unexpected output \"%s\" vs \"%s\"\n", out, expected ); +} + + static void test_DeleteFileA( void ) { BOOL ret; @@ -972,6 +989,7 @@ START_TEST(file) test__llopen( ); test__lread( ); test__lwrite( ); + test_GetTempFileNameA(); test_CopyFileA(); test_CopyFileW(); test_CreateFileA(); diff --git a/files/file.c b/files/file.c index ff3cf60b862..9b4a21c8d74 100644 --- a/files/file.c +++ b/files/file.c @@ -905,7 +905,7 @@ UINT WINAPI GetTempFileNameA( LPCSTR path, LPCSTR prefix, UINT unique, UINT WINAPI GetTempFileNameW( LPCWSTR path, LPCWSTR prefix, UINT unique, LPWSTR buffer ) { - static const WCHAR formatW[] = {'%','0','4','x','.','t','m','p',0}; + static const WCHAR formatW[] = {'%','x','.','t','m','p',0}; DOS_FULL_NAME full_name; int i; @@ -920,9 +920,8 @@ UINT WINAPI GetTempFileNameW( LPCWSTR path, LPCWSTR prefix, UINT unique, strcpyW( buffer, path ); p = buffer + strlenW(buffer); - /* add a \, if there isn't one and path is more than just the drive letter ... */ - if ( !((strlenW(buffer) == 2) && (buffer[1] == ':')) - && ((p == buffer) || (p[-1] != '\\'))) *p++ = '\\'; + /* add a \, if there isn't one */ + if ((p == buffer) || (p[-1] != '\\')) *p++ = '\\'; for (i = 3; (i > 0) && (*prefix); i--) *p++ = *prefix++;