Commit 27ff2ae9 authored by Piotr Caban's avatar Piotr Caban Committed by Alexandre Julliard

msvcrt: Improved locale initialization.

parent 3b4cc446
......@@ -43,8 +43,8 @@ WINE_DEFAULT_DEBUG_CHANNEL(msvcrt);
MSVCRT__locale_t MSVCRT_locale = NULL;
int MSVCRT___lc_codepage = 0;
int MSVCRT___lc_collate_cp = 0;
HANDLE MSVCRT___lc_handle[MSVCRT_LC_MAX - MSVCRT_LC_MIN + 1] = { 0 };
unsigned char charmax = CHAR_MAX;
LCID MSVCRT___lc_handle[MSVCRT_LC_MAX - MSVCRT_LC_MIN + 1] = { 0 };
static unsigned char charmax = CHAR_MAX;
/* MT */
#define LOCK_LOCALE _mlock(_SETLOCALE_LOCK);
......@@ -572,7 +572,7 @@ int CDECL __lconv_init(void)
/*********************************************************************
* ___lc_handle_func (MSVCRT.@)
*/
HANDLE * CDECL ___lc_handle_func(void)
LCID* CDECL ___lc_handle_func(void)
{
return MSVCRT___lc_handle;
}
......@@ -1234,10 +1234,14 @@ char* CDECL MSVCRT_setlocale(int category, const char* locale)
UNLOCK_LOCALE;
if(locinfo == MSVCRT_locale->locinfo) {
int i;
MSVCRT___lc_codepage = locinfo->lc_codepage;
MSVCRT___lc_collate_cp = locinfo->lc_collate_cp;
MSVCRT___mb_cur_max = locinfo->mb_cur_max;
MSVCRT__pctype = locinfo->pctype;
for(i=MSVCRT_LC_MIN; i<=MSVCRT_LC_MAX; i++)
MSVCRT___lc_handle[i] = MSVCRT_locale->locinfo->lc_handle[i];
}
if(category == MSVCRT_LC_ALL)
......@@ -1291,3 +1295,22 @@ int CDECL _configthreadlocale(int type)
return -1;
}
BOOL msvcrt_init_locale(void)
{
int i;
LOCK_LOCALE;
MSVCRT_locale = MSVCRT__create_locale(0, "C");
UNLOCK_LOCALE;
if(!MSVCRT_locale)
return FALSE;
MSVCRT___lc_codepage = MSVCRT_locale->locinfo->lc_codepage;
MSVCRT___lc_collate_cp = MSVCRT_locale->locinfo->lc_collate_cp;
MSVCRT___mb_cur_max = MSVCRT_locale->locinfo->mb_cur_max;
MSVCRT__pctype = MSVCRT_locale->locinfo->pctype;
for(i=MSVCRT_LC_MIN; i<=MSVCRT_LC_MAX; i++)
MSVCRT___lc_handle[i] = MSVCRT_locale->locinfo->lc_handle[i];
return TRUE;
}
......@@ -74,8 +74,10 @@ static inline void msvcrt_free_tls_mem(void)
HeapFree(GetProcessHeap(),0,tls->strerror_buffer);
HeapFree(GetProcessHeap(),0,tls->wcserror_buffer);
HeapFree(GetProcessHeap(),0,tls->time_buffer);
free_locinfo(tls->locinfo);
free_mbcinfo(tls->mbcinfo);
if(tls->have_locale) {
free_locinfo(tls->locinfo);
free_mbcinfo(tls->mbcinfo);
}
}
HeapFree(GetProcessHeap(), 0, tls);
}
......@@ -96,7 +98,7 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
if (!msvcrt_init_tls())
return FALSE;
msvcrt_init_mt_locks();
if(!(MSVCRT_locale = MSVCRT__create_locale(0, "C"))) {
if(!msvcrt_init_locale()) {
msvcrt_free_mt_locks();
msvcrt_free_tls_mem();
return FALSE;
......
......@@ -112,7 +112,7 @@ typedef struct MSVCRT_threadlocaleinfostruct {
int refcount;
unsigned int lc_codepage;
unsigned int lc_collate_cp;
unsigned long lc_handle[6];
MSVCRT_ulong lc_handle[6];
MSVCRT_LC_ID lc_id[6];
struct {
char *locale;
......@@ -234,6 +234,7 @@ extern char* __cdecl __unDNameEx(char *,const char*,int,malloc_func_t,free_func_
extern void msvcrt_init_mt_locks(void);
extern void msvcrt_free_mt_locks(void);
extern BOOL msvcrt_init_locale(void);
extern void msvcrt_init_math(void);
extern void msvcrt_init_io(void);
extern void msvcrt_free_io(void);
......@@ -881,7 +882,6 @@ int __cdecl MSVCRT_raise(int sig);
#define MSVCRT__DISABLE_PER_THREAD_LOCALE 2
extern MSVCRT__locale_t MSVCRT_locale;
MSVCRT__locale_t MSVCRT__create_locale(int, const char*);
MSVCRT_pthreadlocinfo get_locinfo(void);
void __cdecl MSVCRT__free_locale(MSVCRT__locale_t);
void free_locinfo(MSVCRT_pthreadlocinfo);
......
......@@ -212,7 +212,7 @@ typedef struct threadlocaleinfostruct {
int refcount;
unsigned int lc_codepage;
unsigned int lc_collate_cp;
unsigned long lc_handle[6];
__msvcrt_ulong lc_handle[6];
LC_ID lc_id[6];
struct {
char *locale;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment