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

Reply via email to