| 1 | /** |
| 2 | * This file has no copyright assigned and is placed in the Public Domain. |
| 3 | * This file is part of the mingw-w64 runtime package. |
| 4 | * No warranty is given; refer to the file DISCLAIMER.PD within this package. |
| 5 | */ |
| 6 | |
| 7 | #ifndef WIN32_LEAN_AND_MEAN |
| 8 | #define WIN32_LEAN_AND_MEAN |
| 9 | #endif |
| 10 | #include <windows.h> |
| 11 | #include <locale.h> |
| 12 | |
| 13 | /* By default the ANSI (ACP) is used, fallack to default ANSI when function AreFileApisANSI() is not available */ |
| 14 | static BOOL WINAPI fallbackAreFileApisANSI(VOID) { return TRUE; } |
| 15 | |
| 16 | unsigned int __cdecl __mingw_filename_cp(void) |
| 17 | { |
| 18 | if (___lc_codepage_func() == CP_UTF8) |
| 19 | return CP_UTF8; |
| 20 | |
| 21 | /* Function AreFileApisANSI() is not available in older Windows versions, so resolve it at runtime */ |
| 22 | static __typeof__(AreFileApisANSI) *myAreFileApisANSI = NULL; |
| 23 | if (!myAreFileApisANSI) { |
| 24 | FARPROC farproc = NULL; |
| 25 | HMODULE kernel32 = GetModuleHandleA("kernel32.dll"); |
| 26 | if (kernel32) |
| 27 | farproc = GetProcAddress(kernel32, "AreFileApisANSI"); |
| 28 | if (!farproc) |
| 29 | farproc = (FARPROC)(PVOID)fallbackAreFileApisANSI; |
| 30 | (void)InterlockedExchangePointer((PVOID*)&myAreFileApisANSI, (PVOID)farproc); |
| 31 | } |
| 32 | return myAreFileApisANSI() ? CP_ACP : CP_OEMCP; |
| 33 | } |