I have a funny feeling that ancient systems which do not have AreFileApisANSI may use OEM code page for filenames, but I do not have a way to verify it.
Remember that crtdll.dll and msvcrt10.dll use OEM code pages by default, this makes me think that such ancient system would use OEM code pages in general. - Kirill Makurin ________________________________ From: Pali Rohár <[email protected]> Sent: Wednesday, December 31, 2025 3:29 AM To: [email protected] <[email protected]> Subject: [Mingw-w64-public] [PATCH 1/3] crt: Improve __mingw_filename_cp() to work on systems without AreFileApisANSI() function It the AreFileApisANSI() function is not available then fallback to the default value that ANSI (ACP) encoding for filenames is used. --- mingw-w64-crt/misc/__mingw_filename_cp.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/mingw-w64-crt/misc/__mingw_filename_cp.c b/mingw-w64-crt/misc/__mingw_filename_cp.c index f6de486e983b..4fc92fcb269f 100644 --- a/mingw-w64-crt/misc/__mingw_filename_cp.c +++ b/mingw-w64-crt/misc/__mingw_filename_cp.c @@ -10,9 +10,20 @@ #include <windows.h> #include <locale.h> +/* By default the ANSI (ACP) is used, fallack to default ANSI when function AreFileApisANSI() is not available */ +static BOOL WINAPI fallbackAreFileApisANSI(VOID) { return TRUE; } + unsigned int __cdecl __mingw_filename_cp(void) { - return (___lc_codepage_func() == CP_UTF8) - ? CP_UTF8 - : AreFileApisANSI() ? CP_ACP : CP_OEMCP; + if (___lc_codepage_func() == CP_UTF8) + return CP_UTF8; + + /* Function AreFileApisANSI() is not available in older Windows versions, so resolve it at runtime */ + static BOOL (WINAPI *myAreFileApisANSI)(VOID) = NULL; + if (!myAreFileApisANSI) { + HMODULE kernel32 = GetModuleHandleA("kernel32.dll"); + FARPROC farproc = kernel32 ? GetProcAddress(kernel32, "AreFileApisANSI") : NULL; + (void)InterlockedExchangePointer((PVOID*)&myAreFileApisANSI, farproc ?: fallbackAreFileApisANSI); + } + return myAreFileApisANSI() ? CP_ACP : CP_OEMCP; } -- 2.20.1 _______________________________________________ Mingw-w64-public mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/mingw-w64-public _______________________________________________ Mingw-w64-public mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/mingw-w64-public
