• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #define __lc_codepage __dummy_lc_codepage
2 #define ___lc_codepage_func __dummy____lc_codepage_func
3 #include <windows.h>
4 #include <locale.h>
5 #include <msvcrt.h>
6 
7 #undef __lc_codepage
8 #undef ___lc_codepage_func
9 #include "mb_wc_common.h"
10 
11 static unsigned int *msvcrt__lc_codepage;
msvcrt___lc_codepage_func(void)12 static unsigned int __cdecl msvcrt___lc_codepage_func(void)
13 {
14     return *msvcrt__lc_codepage;
15 }
16 
setlocale_codepage_hack(void)17 static unsigned int __cdecl setlocale_codepage_hack(void)
18 {
19     /* locale :: "lang[_country[.code_page]]" | ".code_page"  */
20     const char *cp_str = strchr (setlocale(LC_CTYPE, NULL), '.');
21     return cp_str ? atoi(cp_str + 1) : 0;
22 }
23 
24 static unsigned int __cdecl init_codepage_func(void);
25 unsigned int (__cdecl *__MINGW_IMP_SYMBOL(___lc_codepage_func))(void) = init_codepage_func;
26 
___lc_codepage_func(void)27 unsigned int __cdecl ___lc_codepage_func (void)
28 {
29   return __MINGW_IMP_SYMBOL(___lc_codepage_func) ();
30 }
31 
init_codepage_func(void)32 static unsigned int __cdecl init_codepage_func(void)
33 {
34     HMODULE msvcrt = __mingw_get_msvcrt_handle();
35     unsigned int (__cdecl *func)(void) = NULL;
36 
37     if(msvcrt) {
38         func = (void*)GetProcAddress(msvcrt, "___lc_codepage_func");
39         if(!func) {
40             msvcrt__lc_codepage = (unsigned int*)GetProcAddress(msvcrt, "__lc_codepage");
41             if(msvcrt__lc_codepage)
42                 func = msvcrt___lc_codepage_func;
43         }
44     }
45 
46     if(!func)
47         func = setlocale_codepage_hack;
48 
49     return (__MINGW_IMP_SYMBOL(___lc_codepage_func) = func)();
50 }
51