9191#endif
9292
9393#include <windows.h>
94+ #include <pathcch.h>
9495#include <shlwapi.h>
9596
9697#ifdef HAVE_SYS_TYPES_H
@@ -242,42 +243,14 @@ ismodule(wchar_t *filename, int update_filename)
242243 stuff as fits will be appended.
243244*/
244245
245- static int _PathCchCombineEx_Initialized = 0 ;
246- typedef HRESULT (__stdcall * PPathCchCombineEx ) (PWSTR pszPathOut , size_t cchPathOut ,
247- PCWSTR pszPathIn , PCWSTR pszMore ,
248- unsigned long dwFlags );
249- static PPathCchCombineEx _PathCchCombineEx ;
250-
251246static void
252247join (wchar_t * buffer , const wchar_t * stuff )
253248{
254- if (_PathCchCombineEx_Initialized == 0 ) {
255- HMODULE pathapi = LoadLibraryW (L"api-ms-win-core-path-l1-1-0.dll" );
256- if (pathapi ) {
257- _PathCchCombineEx = (PPathCchCombineEx )GetProcAddress (pathapi , "PathCchCombineEx" );
258- }
259- else {
260- _PathCchCombineEx = NULL ;
261- }
262- _PathCchCombineEx_Initialized = 1 ;
263- }
264-
265- if (_PathCchCombineEx ) {
266- if (FAILED (_PathCchCombineEx (buffer , MAXPATHLEN + 1 , buffer , stuff , 0 ))) {
267- Py_FatalError ("buffer overflow in getpathp.c's join()" );
268- }
269- } else {
270- if (!PathCombineW (buffer , buffer , stuff )) {
271- Py_FatalError ("buffer overflow in getpathp.c's join()" );
272- }
249+ if (FAILED (PathCchCombineEx (buffer , MAXPATHLEN + 1 , buffer , stuff , 0 ))) {
250+ Py_FatalError ("buffer overflow in getpathp.c's join()" );
273251 }
274252}
275253
276- static int _PathCchCanonicalizeEx_Initialized = 0 ;
277- typedef HRESULT (__stdcall * PPathCchCanonicalizeEx ) (PWSTR pszPathOut , size_t cchPathOut ,
278- PCWSTR pszPathIn , unsigned long dwFlags );
279- static PPathCchCanonicalizeEx _PathCchCanonicalizeEx ;
280-
281254/* Call PathCchCanonicalizeEx(path): remove navigation elements such as "."
282255 and ".." to produce a direct, well-formed path. */
283256static PyStatus
@@ -287,26 +260,8 @@ canonicalize(wchar_t *buffer, const wchar_t *path)
287260 return _PyStatus_NO_MEMORY ();
288261 }
289262
290- if (_PathCchCanonicalizeEx_Initialized == 0 ) {
291- HMODULE pathapi = LoadLibraryW (L"api-ms-win-core-path-l1-1-0.dll" );
292- if (pathapi ) {
293- _PathCchCanonicalizeEx = (PPathCchCanonicalizeEx )GetProcAddress (pathapi , "PathCchCanonicalizeEx" );
294- }
295- else {
296- _PathCchCanonicalizeEx = NULL ;
297- }
298- _PathCchCanonicalizeEx_Initialized = 1 ;
299- }
300-
301- if (_PathCchCanonicalizeEx ) {
302- if (FAILED (_PathCchCanonicalizeEx (buffer , MAXPATHLEN + 1 , path , 0 ))) {
303- return INIT_ERR_BUFFER_OVERFLOW ();
304- }
305- }
306- else {
307- if (!PathCanonicalizeW (buffer , path )) {
308- return INIT_ERR_BUFFER_OVERFLOW ();
309- }
263+ if (FAILED (PathCchCanonicalizeEx (buffer , MAXPATHLEN + 1 , path , 0 ))) {
264+ return INIT_ERR_BUFFER_OVERFLOW ();
310265 }
311266 return _PyStatus_OK ();
312267}
0 commit comments