91
91
#endif
92
92
93
93
#include <windows.h>
94
+ #include <pathcch.h>
94
95
#include <shlwapi.h>
95
96
96
97
#ifdef HAVE_SYS_TYPES_H
@@ -242,42 +243,14 @@ ismodule(wchar_t *filename, int update_filename)
242
243
stuff as fits will be appended.
243
244
*/
244
245
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
-
251
246
static void
252
247
join (wchar_t * buffer , const wchar_t * stuff )
253
248
{
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()" );
273
251
}
274
252
}
275
253
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
-
281
254
/* Call PathCchCanonicalizeEx(path): remove navigation elements such as "."
282
255
and ".." to produce a direct, well-formed path. */
283
256
static PyStatus
@@ -287,26 +260,8 @@ canonicalize(wchar_t *buffer, const wchar_t *path)
287
260
return _PyStatus_NO_MEMORY ();
288
261
}
289
262
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 ();
310
265
}
311
266
return _PyStatus_OK ();
312
267
}
0 commit comments