crt: Add a compatibility wrapper for _get_current_locale This function only exists since Windows 8, but is is currently used by libc++. This fixes linker errors with libc++ when linking against msvcrt.dll. This compatibility wrapper only returns NULL and doesn't attempt keeping track of what the last set locale actually was. (Doing that is a bit hard as well, since _get_current_locale is supposed to allocate and populate a _locale_t struct, while setlocale only gets a locale name string.) The parts of libc++ using this function probably won't work perfectly on versions prior to Windows 8 with this wrapper, but this allows building libc++ in general for a wider range of Windows versions, and having these parts working as intended on Windows 8 and newer. Signed-off-by: Martin Storsjö <martin@martin.st>
diff --git a/mingw-w64-crt/Makefile.am b/mingw-w64-crt/Makefile.am index eaa0080..8ee5a22 100644 --- a/mingw-w64-crt/Makefile.am +++ b/mingw-w64-crt/Makefile.am
@@ -155,6 +155,7 @@ src_msvcrt=\ misc/_configthreadlocale.c \ + misc/_get_current_locale.c \ misc/invalid_parameter_handler.c \ misc/output_format.c \ misc/purecall.c \
diff --git a/mingw-w64-crt/misc/_get_current_locale.c b/mingw-w64-crt/misc/_get_current_locale.c new file mode 100644 index 0000000..f5ccc4a --- /dev/null +++ b/mingw-w64-crt/misc/_get_current_locale.c
@@ -0,0 +1,26 @@ +#include <windows.h> +#include <locale.h> +#include <msvcrt.h> + +static _locale_t __cdecl init_func(void); +_locale_t (__cdecl *__MINGW_IMP_SYMBOL(_get_current_locale))(void) = init_func; + +static _locale_t __cdecl null_func(void) +{ + return NULL; +} + +static _locale_t __cdecl init_func(void) +{ + HMODULE msvcrt = __mingw_get_msvcrt_handle(); + _locale_t (__cdecl *func)(void) = NULL; + + if (msvcrt) { + func = (void*)GetProcAddress(msvcrt, "_get_current_locale"); + } + + if (!func) + func = null_func; + + return (__MINGW_IMP_SYMBOL(_get_current_locale) = func)(); +}
diff --git a/mingw-w64-headers/crt/locale.h b/mingw-w64-headers/crt/locale.h index b6bae04..1f588e8 100644 --- a/mingw-w64-headers/crt/locale.h +++ b/mingw-w64-headers/crt/locale.h
@@ -79,7 +79,7 @@ int __cdecl _configthreadlocale(int _Flag); char *__cdecl setlocale(int _Category,const char *_Locale); _CRTIMP struct lconv *__cdecl localeconv(void); - _locale_t __cdecl _get_current_locale(void); + _CRTIMP _locale_t __cdecl _get_current_locale(void); _locale_t __cdecl _create_locale(int _Category,const char *_Locale); void __cdecl _free_locale(_locale_t _Locale); _locale_t __cdecl __get_current_locale(void);