#endif
#include <windows.h>
+#include <pathcch.h>
#include <shlwapi.h>
#ifdef HAVE_SYS_TYPES_H
stuff as fits will be appended.
*/
-static int _PathCchCombineEx_Initialized = 0;
-typedef HRESULT(__stdcall *PPathCchCombineEx) (PWSTR pszPathOut, size_t cchPathOut,
- PCWSTR pszPathIn, PCWSTR pszMore,
- unsigned long dwFlags);
-static PPathCchCombineEx _PathCchCombineEx;
-
static void
join(wchar_t *buffer, const wchar_t *stuff)
{
- if (_PathCchCombineEx_Initialized == 0) {
- HMODULE pathapi = LoadLibraryW(L"api-ms-win-core-path-l1-1-0.dll");
- if (pathapi) {
- _PathCchCombineEx = (PPathCchCombineEx)GetProcAddress(pathapi, "PathCchCombineEx");
- }
- else {
- _PathCchCombineEx = NULL;
- }
- _PathCchCombineEx_Initialized = 1;
- }
-
- if (_PathCchCombineEx) {
- if (FAILED(_PathCchCombineEx(buffer, MAXPATHLEN+1, buffer, stuff, 0))) {
- Py_FatalError("buffer overflow in getpathp.c's join()");
- }
- } else {
- if (!PathCombineW(buffer, buffer, stuff)) {
- Py_FatalError("buffer overflow in getpathp.c's join()");
- }
+ if (FAILED(PathCchCombineEx(buffer, MAXPATHLEN+1, buffer, stuff, 0))) {
+ Py_FatalError("buffer overflow in getpathp.c's join()");
}
}
-static int _PathCchCanonicalizeEx_Initialized = 0;
-typedef HRESULT(__stdcall *PPathCchCanonicalizeEx) (PWSTR pszPathOut, size_t cchPathOut,
- PCWSTR pszPathIn, unsigned long dwFlags);
-static PPathCchCanonicalizeEx _PathCchCanonicalizeEx;
-
static _PyInitError canonicalize(wchar_t *buffer, const wchar_t *path)
{
if (buffer == NULL) {
return _Py_INIT_NO_MEMORY();
}
- if (_PathCchCanonicalizeEx_Initialized == 0) {
- HMODULE pathapi = LoadLibraryW(L"api-ms-win-core-path-l1-1-0.dll");
- if (pathapi) {
- _PathCchCanonicalizeEx = (PPathCchCanonicalizeEx)GetProcAddress(pathapi, "PathCchCanonicalizeEx");
- }
- else {
- _PathCchCanonicalizeEx = NULL;
- }
- _PathCchCanonicalizeEx_Initialized = 1;
- }
-
- if (_PathCchCanonicalizeEx) {
- if (FAILED(_PathCchCanonicalizeEx(buffer, MAXPATHLEN + 1, path, 0))) {
- return _Py_INIT_ERR("buffer overflow in getpathp.c's canonicalize()");
- }
- }
- else {
- if (!PathCanonicalizeW(buffer, path)) {
- return _Py_INIT_ERR("buffer overflow in getpathp.c's canonicalize()");
- }
+ if (FAILED(PathCchCanonicalizeEx(buffer, MAXPATHLEN + 1, path, 0))) {
+ return INIT_ERR_BUFFER_OVERFLOW();
}
return _Py_INIT_OK();
}