Skip to content

Commit 6001814

Browse files
committed
simplify FindTempDirectoryW
1 parent 906d25d commit 6001814

File tree

1 file changed

+10
-44
lines changed

1 file changed

+10
-44
lines changed

win32ss/user/user32/windows/cursoricon.c

Lines changed: 10 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -34,57 +34,23 @@ typedef struct
3434
} CURSORICONFILEDIR;
3535
#include "poppack.h"
3636

37-
WCHAR* FindTempDirectoryW(void)
37+
LPWSTR FindTempDirectoryW(VOID)
3838
{
39-
static WCHAR lpTempPathBuffer[MAX_PATH + 1];
40-
WCHAR *out = lpTempPathBuffer;
41-
DWORD dwRetVal = 0;
42-
FILE * fp;
43-
DWORD dwAttrib;
39+
static WCHAR s_szTempFileName[MAX_PATH];
40+
WCHAR szTempPath[MAX_PATH];
41+
DWORD cchTemp;
4442

45-
/* Gets the temp path env string. Not guaranteed to be valid. */
46-
dwRetVal = GetTempPathW(MAX_PATH * 2, lpTempPathBuffer);
43+
cchTemp = GetTempPathW(_countof(szTempPath), szTempPath);
4744

48-
if (dwRetVal > MAX_PATH || (dwRetVal == 0))
45+
if (!cchTemp || cchTemp > _countof(szTempPath) ||
46+
!GetTempFileNameW(szTempPath, L"png", 0, s_szTempFileName))
4947
{
5048
ERR("Find Temp Directory Failed\n");
51-
goto exit_error;
52-
}
53-
54-
dwAttrib = GetFileAttributesW(lpTempPathBuffer);
55-
if (dwAttrib != INVALID_FILE_ATTRIBUTES &&
56-
(dwAttrib & FILE_ATTRIBUTE_DIRECTORY))
57-
TRACE("Temp Subdir OK\n");
58-
else
59-
goto exit_error;
60-
61-
if (dwRetVal + sizeof(L"bmpout.ico1")> MAX_PATH)
62-
{
63-
ERR("Not Enough working room\n");
64-
goto exit_error;
65-
}
66-
else
67-
{
68-
wcscat(lpTempPathBuffer, L"bmpout.ico1");
69-
}
70-
71-
fp = _wfopen(lpTempPathBuffer, L"wb");
72-
if (!fp)
73-
{
74-
ERR("Temp Directory Path File Open Failed\n");
75-
goto exit_error;
76-
}
77-
else
78-
{
79-
fclose(fp);
49+
return NULL;
8050
}
8151

82-
_wremove(lpTempPathBuffer);
83-
lpTempPathBuffer[wcslen(lpTempPathBuffer) - 1] = 0;
84-
85-
return out;
86-
exit_error:
87-
return 0;
52+
DeleteFileW(s_szTempFileName);
53+
return s_szTempFileName;
8854
}
8955

9056
/* libpng defines */

0 commit comments

Comments
 (0)