Skip to content

Commit

Permalink
Drop fallback for PathCchCanonicalizeEx() (GH-16341)
Browse files Browse the repository at this point in the history
This function is only available as of Windows 8 and Windows Server 2012,
respectively, and thus needed a fallback (albeit a non working one).
However, as of PHP 8.3.0 Windows 8/Server 2012 is required anyway, so
we can drop the fallback as well as the dynamic loading in favor of
linking to the import library.
  • Loading branch information
cmb69 authored Oct 10, 2024
1 parent 018e7f5 commit 6e172f0
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 40 deletions.
2 changes: 1 addition & 1 deletion win32/build/confutils.js
Original file line number Diff line number Diff line change
Expand Up @@ -3426,7 +3426,7 @@ function toolset_setup_common_ldlags()
function toolset_setup_common_libs()
{
// urlmon.lib ole32.lib oleaut32.lib uuid.lib gdi32.lib winspool.lib comdlg32.lib
DEFINE("LIBS", "kernel32.lib ole32.lib user32.lib advapi32.lib shell32.lib ws2_32.lib Dnsapi.lib psapi.lib bcrypt.lib");
DEFINE("LIBS", "kernel32.lib ole32.lib user32.lib advapi32.lib shell32.lib ws2_32.lib Dnsapi.lib psapi.lib bcrypt.lib Pathcch.lib");
}

function toolset_setup_build_mode()
Expand Down
10 changes: 2 additions & 8 deletions win32/dllmain.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#include <config.w32.h>

#include <php.h>
#include <win32/ioutil.h>

#ifdef HAVE_LIBXML
#include <libxml/threads.h>
Expand All @@ -34,16 +33,11 @@ BOOL WINAPI DllMain(HINSTANCE inst, DWORD reason, LPVOID dummy)
{
BOOL ret = TRUE;

#if 0 /* prepared */
switch (reason)
{
case DLL_PROCESS_ATTACH:
ret = ret && php_win32_ioutil_init();
if (!ret) {
fprintf(stderr, "ioutil initialization failed");
return ret;
}
break;
#if 0 /* prepared */
case DLL_PROCESS_DETACH:
/* pass */
break;
Expand All @@ -55,8 +49,8 @@ BOOL WINAPI DllMain(HINSTANCE inst, DWORD reason, LPVOID dummy)
case DLL_THREAD_DETACH:
/* pass */
break;
#endif
}
#endif

#ifdef HAVE_LIBXML
/* This imply that only LIBXML_STATIC_FOR_DLL is supported ATM.
Expand Down
27 changes: 1 addition & 26 deletions win32/ioutil.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,6 @@
#include <winnls.h>
*/

typedef HRESULT (__stdcall *MyPathCchCanonicalizeEx)(wchar_t *pszPathOut, size_t cchPathOut, const wchar_t *pszPathIn, unsigned long dwFlags);

static MyPathCchCanonicalizeEx canonicalize_path_w = NULL;

PW32IO BOOL php_win32_ioutil_posix_to_open_opts(int flags, mode_t mode, php_ioutil_open_opts *opts)
{/*{{{*/
int current_umask;
Expand Down Expand Up @@ -619,7 +615,7 @@ PW32IO php_win32_ioutil_normalization_result php_win32_ioutil_normalize_path_w(w
}
}

if (S_OK != canonicalize_path_w(canonicalw, MAXPATHLEN, _tmp, PATHCCH_ALLOW_LONG_PATHS)) {
if (S_OK != PathCchCanonicalizeEx(canonicalw, MAXPATHLEN, _tmp, PATHCCH_ALLOW_LONG_PATHS)) {
/* Length unchanged. */
*new_len = len;
return PHP_WIN32_IOUTIL_NORM_PARTIAL;
Expand All @@ -643,27 +639,6 @@ PW32IO php_win32_ioutil_normalization_result php_win32_ioutil_normalize_path_w(w
return PHP_WIN32_IOUTIL_NORM_OK;
}/*}}}*/

static HRESULT __stdcall MyPathCchCanonicalizeExFallback(wchar_t *pszPathOut, size_t cchPathOut, const wchar_t *pszPathIn, unsigned long dwFlags)
{/*{{{*/
return -42;
}/*}}}*/

BOOL php_win32_ioutil_init(void)
{/*{{{*/
HMODULE hMod = GetModuleHandle("api-ms-win-core-path-l1-1-0");

if (hMod) {
canonicalize_path_w = (MyPathCchCanonicalizeEx)GetProcAddress(hMod, "PathCchCanonicalizeEx");
if (!canonicalize_path_w) {
canonicalize_path_w = (MyPathCchCanonicalizeEx)MyPathCchCanonicalizeExFallback;
}
} else {
canonicalize_path_w = (MyPathCchCanonicalizeEx)MyPathCchCanonicalizeExFallback;
}

return TRUE;
}/*}}}*/

PW32IO int php_win32_ioutil_access_w(const wchar_t *path, mode_t mode)
{/*{{{*/
DWORD attr;
Expand Down
5 changes: 0 additions & 5 deletions win32/ioutil.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,11 +169,6 @@ typedef enum {
} while (0);

PW32IO php_win32_ioutil_normalization_result php_win32_ioutil_normalize_path_w(wchar_t **buf, size_t len, size_t *new_len);
#ifdef PHP_EXPORTS
/* This symbols are needed only for the DllMain, but should not be exported
or be available when used with PHP binaries. */
BOOL php_win32_ioutil_init(void);
#endif

/* Keep these functions aliased for case some additional handling
is needed later. */
Expand Down

0 comments on commit 6e172f0

Please sign in to comment.