2007-03-14 20:24:57 +00:00
|
|
|
/*
|
2012-12-09 03:17:14 +00:00
|
|
|
* msvcrt.dll locale functions
|
2007-03-14 20:24:57 +00:00
|
|
|
*
|
|
|
|
* Copyright 2000 Jon Griffiths
|
2012-12-09 03:17:14 +00:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2007-03-14 20:24:57 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <precomp.h>
|
|
|
|
#include <locale.h>
|
2008-05-27 08:11:06 +00:00
|
|
|
|
2008-06-06 17:49:24 +00:00
|
|
|
#include "mbctype.h"
|
2012-12-09 03:17:14 +00:00
|
|
|
#include <internal/wine/msvcrt.h>
|
2007-03-14 20:24:57 +00:00
|
|
|
|
2008-05-27 08:11:06 +00:00
|
|
|
#define MAX_ELEM_LEN 64 /* Max length of country/language/CP string */
|
2012-12-09 03:17:14 +00:00
|
|
|
#define MAX_LOCALE_LENGTH 256
|
2008-06-06 17:49:24 +00:00
|
|
|
|
2012-12-09 03:17:14 +00:00
|
|
|
#ifdef _pctype
|
|
|
|
#error _pctype should not be defined
|
|
|
|
#endif
|
2008-06-06 17:49:24 +00:00
|
|
|
|
2012-12-13 21:13:06 +00:00
|
|
|
unsigned int __lc_codepage = 0;
|
2008-07-26 11:45:59 +00:00
|
|
|
int MSVCRT___lc_collate_cp = 0;
|
2012-12-09 03:17:14 +00:00
|
|
|
LCID MSVCRT___lc_handle[LC_MAX - LC_MIN + 1] = { 0 };
|
[CRT]
- Update file.c to recent wine. (now with locking!)
- implement/enable __wcserror, __wcserror_s, _access_s, _ctime32_s, _ctime64_s,
_cwprintf, _fseeki64, _ftelli64, _get_osplatform, _get_output_format,
_get_pgmptr, _get_wpgmptr, _get_terminate, _get_tzname, _get_unexpected,
_gmtime64_s, _i64toa_s, _i64tow_s, _initterm_e, _itoa_s, _itow_s,
_localtime32_s, _localtime64_s, _ltoa_s, _ltow_s, _putwch, _searchenv_s,
_sopen_s, _ui64toa_s, _ui64tow_s, _vcwprintf, _vsprintf_p, _waccess_s,
_wcserror, _wcserror_s, _wfopen_s, _wsopen_s, fopen_s, fprintf_s, fwprintf_s,
printf_s, strerror_s, strncpy_s, strtok_s, vfprintf_s, vfwprintf_s, vprintf_s,
vwprintf_s, wcscat_s, wcsncat_s, wcstok_s, wprintf_s. Most code comes from
wine.
- Fix __set_errno -> _set_errno and export it.
- Remove unneeded files.
[CRT_HEADERS]
- add threadmbcinfo struct.
- update some sec_api headers from mingw64 due to missing or incorrect
functions.
Patch by Samuel Serapion.
Changes to msvcrt spec by me due to winebuild.
CRLF/LF fixes.
svn path=/trunk/; revision=54651
2011-12-14 22:09:24 +00:00
|
|
|
int __mb_cur_max = 1;
|
2012-12-09 03:17:14 +00:00
|
|
|
static unsigned char charmax = CHAR_MAX;
|
|
|
|
|
|
|
|
unsigned char _mbctype[257] = { 0 };
|
2008-05-27 08:11:06 +00:00
|
|
|
|
|
|
|
/* MT */
|
|
|
|
#define LOCK_LOCALE _mlock(_SETLOCALE_LOCK);
|
|
|
|
#define UNLOCK_LOCALE _munlock(_SETLOCALE_LOCK);
|
|
|
|
|
|
|
|
#define MSVCRT_LEADBYTE 0x8000
|
2012-12-09 03:17:14 +00:00
|
|
|
#define MSVCRT_C1_DEFINED 0x200
|
2008-05-27 08:11:06 +00:00
|
|
|
|
2012-12-09 03:17:14 +00:00
|
|
|
/* Friendly country strings & language names abbreviations. */
|
2008-05-27 08:11:06 +00:00
|
|
|
static const char * const _country_synonyms[] =
|
|
|
|
{
|
2012-12-09 03:17:14 +00:00
|
|
|
"american", "enu",
|
|
|
|
"american english", "enu",
|
|
|
|
"american-english", "enu",
|
|
|
|
"english-american", "enu",
|
|
|
|
"english-us", "enu",
|
|
|
|
"english-usa", "enu",
|
|
|
|
"us", "enu",
|
|
|
|
"usa", "enu",
|
|
|
|
"australian", "ena",
|
|
|
|
"english-aus", "ena",
|
|
|
|
"belgian", "nlb",
|
|
|
|
"french-belgian", "frb",
|
|
|
|
"canadian", "enc",
|
|
|
|
"english-can", "enc",
|
|
|
|
"french-canadian", "frc",
|
|
|
|
"chinese", "chs",
|
|
|
|
"chinese-simplified", "chs",
|
|
|
|
"chinese-traditional", "cht",
|
|
|
|
"dutch-belgian", "nlb",
|
|
|
|
"english-nz", "enz",
|
|
|
|
"uk", "eng",
|
|
|
|
"english-uk", "eng",
|
|
|
|
"french-swiss", "frs",
|
|
|
|
"swiss", "des",
|
|
|
|
"german-swiss", "des",
|
|
|
|
"italian-swiss", "its",
|
|
|
|
"german-austrian", "dea",
|
|
|
|
"portuguese", "ptb",
|
|
|
|
"portuguese-brazil", "ptb",
|
|
|
|
"spanish-mexican", "esm",
|
|
|
|
"norwegian-bokmal", "nor",
|
|
|
|
"norwegian-nynorsk", "non",
|
|
|
|
"spanish-modern", "esn"
|
2008-05-27 08:11:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* INTERNAL: Map a synonym to an ISO code */
|
|
|
|
static void remap_synonym(char *name)
|
|
|
|
{
|
2012-12-09 03:17:14 +00:00
|
|
|
unsigned int i;
|
2008-05-27 08:11:06 +00:00
|
|
|
for (i = 0; i < sizeof(_country_synonyms)/sizeof(char*); i += 2 )
|
|
|
|
{
|
2012-12-09 03:17:14 +00:00
|
|
|
if (!strcasecmp(_country_synonyms[i],name))
|
2008-05-27 08:11:06 +00:00
|
|
|
{
|
|
|
|
TRACE(":Mapping synonym %s to %s\n",name,_country_synonyms[i+1]);
|
2012-12-09 03:17:14 +00:00
|
|
|
strcpy(name, _country_synonyms[i+1]);
|
2008-05-27 08:11:06 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-12-09 03:17:14 +00:00
|
|
|
/* Note: Flags are weighted in order of matching importance */
|
|
|
|
#define FOUND_LANGUAGE 0x4
|
|
|
|
#define FOUND_COUNTRY 0x2
|
|
|
|
#define FOUND_CODEPAGE 0x1
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
char search_language[MAX_ELEM_LEN];
|
|
|
|
char search_country[MAX_ELEM_LEN];
|
|
|
|
char search_codepage[MAX_ELEM_LEN];
|
|
|
|
char found_codepage[MAX_ELEM_LEN];
|
|
|
|
unsigned int match_flags;
|
|
|
|
LANGID found_lang_id;
|
|
|
|
} locale_search_t;
|
|
|
|
|
2008-05-27 08:11:06 +00:00
|
|
|
#define CONTINUE_LOOKING TRUE
|
|
|
|
#define STOP_LOOKING FALSE
|
|
|
|
|
|
|
|
/* INTERNAL: Get and compare locale info with a given string */
|
2012-12-09 03:17:14 +00:00
|
|
|
static int compare_info(LCID lcid, DWORD flags, char* buff, const char* cmp, BOOL exact)
|
2008-05-27 08:11:06 +00:00
|
|
|
{
|
2012-12-09 03:17:14 +00:00
|
|
|
int len;
|
|
|
|
|
2013-04-03 22:46:22 +00:00
|
|
|
if(!cmp[0])
|
|
|
|
return 0;
|
|
|
|
|
2008-05-27 08:11:06 +00:00
|
|
|
buff[0] = 0;
|
2012-12-09 03:17:14 +00:00
|
|
|
GetLocaleInfoA(lcid, flags|LOCALE_NOUSEROVERRIDE, buff, MAX_ELEM_LEN);
|
2013-04-03 22:46:22 +00:00
|
|
|
if (!buff[0])
|
2008-05-27 08:11:06 +00:00
|
|
|
return 0;
|
|
|
|
|
2012-12-09 03:17:14 +00:00
|
|
|
/* Partial matches are only allowed on language/country names */
|
|
|
|
len = strlen(cmp);
|
|
|
|
if(exact || len<=3)
|
|
|
|
return !strcasecmp(cmp, buff);
|
|
|
|
else
|
|
|
|
return !strncasecmp(cmp, buff, len);
|
|
|
|
}
|
2008-05-27 08:11:06 +00:00
|
|
|
|
|
|
|
static BOOL CALLBACK
|
|
|
|
find_best_locale_proc(HMODULE hModule, LPCSTR type, LPCSTR name, WORD LangID, LONG_PTR lParam)
|
|
|
|
{
|
|
|
|
locale_search_t *res = (locale_search_t *)lParam;
|
|
|
|
const LCID lcid = MAKELCID(LangID, SORT_DEFAULT);
|
|
|
|
char buff[MAX_ELEM_LEN];
|
|
|
|
unsigned int flags = 0;
|
|
|
|
|
|
|
|
if(PRIMARYLANGID(LangID) == LANG_NEUTRAL)
|
|
|
|
return CONTINUE_LOOKING;
|
|
|
|
|
|
|
|
/* Check Language */
|
2012-12-09 03:17:14 +00:00
|
|
|
if (compare_info(lcid,LOCALE_SISO639LANGNAME,buff,res->search_language, TRUE) ||
|
|
|
|
compare_info(lcid,LOCALE_SABBREVLANGNAME,buff,res->search_language, TRUE) ||
|
|
|
|
compare_info(lcid,LOCALE_SENGLANGUAGE,buff,res->search_language, FALSE))
|
2008-05-27 08:11:06 +00:00
|
|
|
{
|
|
|
|
TRACE(":Found language: %s->%s\n", res->search_language, buff);
|
|
|
|
flags |= FOUND_LANGUAGE;
|
|
|
|
}
|
|
|
|
else if (res->match_flags & FOUND_LANGUAGE)
|
|
|
|
{
|
|
|
|
return CONTINUE_LOOKING;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check Country */
|
2012-12-09 03:17:14 +00:00
|
|
|
if (compare_info(lcid,LOCALE_SISO3166CTRYNAME,buff,res->search_country, TRUE) ||
|
|
|
|
compare_info(lcid,LOCALE_SABBREVCTRYNAME,buff,res->search_country, TRUE) ||
|
|
|
|
compare_info(lcid,LOCALE_SENGCOUNTRY,buff,res->search_country, FALSE))
|
2008-05-27 08:11:06 +00:00
|
|
|
{
|
|
|
|
TRACE("Found country:%s->%s\n", res->search_country, buff);
|
|
|
|
flags |= FOUND_COUNTRY;
|
|
|
|
}
|
2013-04-03 22:46:22 +00:00
|
|
|
else if (!flags && (res->match_flags & FOUND_COUNTRY))
|
2008-05-27 08:11:06 +00:00
|
|
|
{
|
|
|
|
return CONTINUE_LOOKING;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check codepage */
|
2012-12-09 03:17:14 +00:00
|
|
|
if (compare_info(lcid,LOCALE_IDEFAULTCODEPAGE,buff,res->search_codepage, TRUE) ||
|
|
|
|
(compare_info(lcid,LOCALE_IDEFAULTANSICODEPAGE,buff,res->search_codepage, TRUE)))
|
2008-05-27 08:11:06 +00:00
|
|
|
{
|
|
|
|
TRACE("Found codepage:%s->%s\n", res->search_codepage, buff);
|
|
|
|
flags |= FOUND_CODEPAGE;
|
|
|
|
memcpy(res->found_codepage,res->search_codepage,MAX_ELEM_LEN);
|
|
|
|
}
|
2013-04-03 22:46:22 +00:00
|
|
|
else if (!flags && (res->match_flags & FOUND_CODEPAGE))
|
2008-05-27 08:11:06 +00:00
|
|
|
{
|
|
|
|
return CONTINUE_LOOKING;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (flags > res->match_flags)
|
|
|
|
{
|
|
|
|
/* Found a better match than previously */
|
|
|
|
res->match_flags = flags;
|
|
|
|
res->found_lang_id = LangID;
|
|
|
|
}
|
2009-08-15 10:01:28 +00:00
|
|
|
if ((flags & (FOUND_LANGUAGE | FOUND_COUNTRY | FOUND_CODEPAGE)) ==
|
|
|
|
(FOUND_LANGUAGE | FOUND_COUNTRY | FOUND_CODEPAGE))
|
2008-05-27 08:11:06 +00:00
|
|
|
{
|
|
|
|
TRACE(":found exact locale match\n");
|
|
|
|
return STOP_LOOKING;
|
|
|
|
}
|
|
|
|
return CONTINUE_LOOKING;
|
|
|
|
}
|
|
|
|
|
2012-12-09 03:17:14 +00:00
|
|
|
extern int atoi(const char *);
|
|
|
|
|
2008-05-27 08:11:06 +00:00
|
|
|
/* Internal: Find the LCID for a locale specification */
|
2013-04-03 22:46:22 +00:00
|
|
|
LCID MSVCRT_locale_to_LCID(const char *locale, unsigned short *codepage)
|
2008-05-27 08:11:06 +00:00
|
|
|
{
|
2012-12-09 03:17:14 +00:00
|
|
|
LCID lcid;
|
|
|
|
locale_search_t search;
|
|
|
|
const char *cp, *region;
|
|
|
|
|
|
|
|
memset(&search, 0, sizeof(locale_search_t));
|
|
|
|
|
|
|
|
cp = strchr(locale, '.');
|
|
|
|
region = strchr(locale, '_');
|
|
|
|
|
|
|
|
lstrcpynA(search.search_language, locale, MAX_ELEM_LEN);
|
|
|
|
if(region) {
|
|
|
|
lstrcpynA(search.search_country, region+1, MAX_ELEM_LEN);
|
|
|
|
if(region-locale < MAX_ELEM_LEN)
|
|
|
|
search.search_language[region-locale] = '\0';
|
|
|
|
} else
|
|
|
|
search.search_country[0] = '\0';
|
|
|
|
|
|
|
|
if(cp) {
|
|
|
|
lstrcpynA(search.search_codepage, cp+1, MAX_ELEM_LEN);
|
|
|
|
if(region && cp-region-1<MAX_ELEM_LEN)
|
|
|
|
search.search_country[cp-region-1] = '\0';
|
|
|
|
if(cp-locale < MAX_ELEM_LEN)
|
|
|
|
search.search_language[cp-locale] = '\0';
|
|
|
|
} else
|
|
|
|
search.search_codepage[0] = '\0';
|
|
|
|
|
|
|
|
if(!search.search_country[0] && !search.search_codepage[0])
|
|
|
|
remap_synonym(search.search_language);
|
|
|
|
|
|
|
|
EnumResourceLanguagesA(GetModuleHandleA("KERNEL32"), (LPSTR)RT_STRING,
|
|
|
|
(LPCSTR)LOCALE_ILANGUAGE,find_best_locale_proc,
|
|
|
|
(LONG_PTR)&search);
|
|
|
|
|
|
|
|
if (!search.match_flags)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
/* If we were given something that didn't match, fail */
|
|
|
|
if (search.search_country[0] && !(search.match_flags & FOUND_COUNTRY))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
lcid = MAKELCID(search.found_lang_id, SORT_DEFAULT);
|
|
|
|
|
|
|
|
/* Populate partial locale, translating LCID to locale string elements */
|
2013-04-03 22:46:22 +00:00
|
|
|
if (!(search.match_flags & FOUND_CODEPAGE)) {
|
2012-12-09 03:17:14 +00:00
|
|
|
/* Even if a codepage is not enumerated for a locale
|
|
|
|
* it can be set if valid */
|
|
|
|
if (search.search_codepage[0]) {
|
|
|
|
if (IsValidCodePage(atoi(search.search_codepage)))
|
|
|
|
memcpy(search.found_codepage,search.search_codepage,MAX_ELEM_LEN);
|
|
|
|
else {
|
|
|
|
/* Special codepage values: OEM & ANSI */
|
2013-04-03 22:46:22 +00:00
|
|
|
if (!strcasecmp(search.search_codepage,"OCP")) {
|
2012-12-09 03:17:14 +00:00
|
|
|
GetLocaleInfoA(lcid, LOCALE_IDEFAULTCODEPAGE,
|
|
|
|
search.found_codepage, MAX_ELEM_LEN);
|
2013-04-03 22:46:22 +00:00
|
|
|
} else if (!strcasecmp(search.search_codepage,"ACP")) {
|
2012-12-09 03:17:14 +00:00
|
|
|
GetLocaleInfoA(lcid, LOCALE_IDEFAULTANSICODEPAGE,
|
|
|
|
search.found_codepage, MAX_ELEM_LEN);
|
|
|
|
} else
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (!atoi(search.found_codepage))
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* Prefer ANSI codepages if present */
|
|
|
|
GetLocaleInfoA(lcid, LOCALE_IDEFAULTANSICODEPAGE,
|
|
|
|
search.found_codepage, MAX_ELEM_LEN);
|
|
|
|
if (!search.found_codepage[0] || !atoi(search.found_codepage))
|
|
|
|
GetLocaleInfoA(lcid, LOCALE_IDEFAULTCODEPAGE,
|
|
|
|
search.found_codepage, MAX_ELEM_LEN);
|
2008-05-27 08:11:06 +00:00
|
|
|
}
|
|
|
|
}
|
2013-04-03 22:46:22 +00:00
|
|
|
if (codepage)
|
|
|
|
*codepage = atoi(search.found_codepage);
|
2012-12-09 03:17:14 +00:00
|
|
|
|
|
|
|
return lcid;
|
2008-05-27 08:11:06 +00:00
|
|
|
}
|
|
|
|
|
2012-12-09 03:17:14 +00:00
|
|
|
/* INTERNAL: Set lc_handle, lc_id and lc_category in threadlocinfo struct */
|
2013-04-03 22:46:22 +00:00
|
|
|
static BOOL update_threadlocinfo_category(LCID lcid, unsigned short cp,
|
|
|
|
MSVCRT__locale_t loc, int category)
|
2008-05-27 08:11:06 +00:00
|
|
|
{
|
2012-12-09 03:17:14 +00:00
|
|
|
char buf[256], *p;
|
|
|
|
int len;
|
2008-05-27 08:11:06 +00:00
|
|
|
|
2012-12-09 03:17:14 +00:00
|
|
|
if(GetLocaleInfoA(lcid, LOCALE_ILANGUAGE|LOCALE_NOUSEROVERRIDE, buf, 256)) {
|
|
|
|
p = buf;
|
2008-05-27 08:11:06 +00:00
|
|
|
|
2012-12-09 03:17:14 +00:00
|
|
|
loc->locinfo->lc_id[category].wLanguage = 0;
|
|
|
|
while(*p) {
|
|
|
|
loc->locinfo->lc_id[category].wLanguage *= 16;
|
2008-05-27 08:11:06 +00:00
|
|
|
|
2012-12-09 03:17:14 +00:00
|
|
|
if(*p <= '9')
|
|
|
|
loc->locinfo->lc_id[category].wLanguage += *p-'0';
|
|
|
|
else
|
|
|
|
loc->locinfo->lc_id[category].wLanguage += *p-'a'+10;
|
2008-05-27 08:11:06 +00:00
|
|
|
|
2012-12-09 03:17:14 +00:00
|
|
|
p++;
|
|
|
|
}
|
2008-05-27 08:11:06 +00:00
|
|
|
|
2012-12-09 03:17:14 +00:00
|
|
|
loc->locinfo->lc_id[category].wCountry =
|
|
|
|
loc->locinfo->lc_id[category].wLanguage;
|
2008-05-27 08:11:06 +00:00
|
|
|
}
|
|
|
|
|
2013-04-03 22:46:22 +00:00
|
|
|
loc->locinfo->lc_id[category].wCodePage = cp;
|
2012-12-09 03:17:14 +00:00
|
|
|
|
|
|
|
loc->locinfo->lc_handle[category] = lcid;
|
|
|
|
|
|
|
|
len = 0;
|
|
|
|
len += GetLocaleInfoA(lcid, LOCALE_SENGLANGUAGE
|
|
|
|
|LOCALE_NOUSEROVERRIDE, buf, 256);
|
|
|
|
buf[len-1] = '_';
|
|
|
|
len += GetLocaleInfoA(lcid, LOCALE_SENGCOUNTRY
|
|
|
|
|LOCALE_NOUSEROVERRIDE, &buf[len], 256-len);
|
|
|
|
buf[len-1] = '.';
|
2013-04-06 23:14:29 +00:00
|
|
|
sprintf(buf+len, "%u", cp);
|
2013-04-03 22:46:22 +00:00
|
|
|
len += strlen(buf+len)+1;
|
2012-12-09 03:17:14 +00:00
|
|
|
|
2013-04-03 22:46:22 +00:00
|
|
|
loc->locinfo->lc_category[category].locale = MSVCRT_malloc(len);
|
|
|
|
loc->locinfo->lc_category[category].refcount = MSVCRT_malloc(sizeof(int));
|
2012-12-09 03:17:14 +00:00
|
|
|
if(!loc->locinfo->lc_category[category].locale
|
|
|
|
|| !loc->locinfo->lc_category[category].refcount) {
|
2013-04-03 22:46:22 +00:00
|
|
|
MSVCRT_free(loc->locinfo->lc_category[category].locale);
|
|
|
|
MSVCRT_free(loc->locinfo->lc_category[category].refcount);
|
2012-12-09 03:17:14 +00:00
|
|
|
loc->locinfo->lc_category[category].locale = NULL;
|
|
|
|
loc->locinfo->lc_category[category].refcount = NULL;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
memcpy(loc->locinfo->lc_category[category].locale, buf, len);
|
|
|
|
*loc->locinfo->lc_category[category].refcount = 1;
|
|
|
|
|
|
|
|
return FALSE;
|
2008-05-27 08:11:06 +00:00
|
|
|
}
|
|
|
|
|
2012-12-09 03:17:14 +00:00
|
|
|
/* INTERNAL: swap pointers values */
|
|
|
|
static inline void swap_pointers(void **p1, void **p2) {
|
|
|
|
void *hlp;
|
2008-05-27 08:11:06 +00:00
|
|
|
|
2012-12-09 03:17:14 +00:00
|
|
|
hlp = *p1;
|
|
|
|
*p1 = *p2;
|
|
|
|
*p2 = hlp;
|
|
|
|
}
|
2007-03-14 20:24:57 +00:00
|
|
|
|
2012-12-09 03:17:14 +00:00
|
|
|
/* INTERNAL: returns pthreadlocinfo struct */
|
|
|
|
MSVCRT_pthreadlocinfo get_locinfo(void) {
|
|
|
|
thread_data_t *data = msvcrt_get_thread_data();
|
2008-05-27 08:11:06 +00:00
|
|
|
|
2012-12-09 03:17:14 +00:00
|
|
|
if(!data || !data->have_locale)
|
|
|
|
return MSVCRT_locale->locinfo;
|
2008-05-27 08:11:06 +00:00
|
|
|
|
2012-12-09 03:17:14 +00:00
|
|
|
return data->locinfo;
|
|
|
|
}
|
2008-05-27 08:11:06 +00:00
|
|
|
|
2012-12-09 03:17:14 +00:00
|
|
|
/* INTERNAL: returns pthreadlocinfo struct */
|
|
|
|
MSVCRT_pthreadmbcinfo get_mbcinfo(void) {
|
|
|
|
thread_data_t *data = msvcrt_get_thread_data();
|
2008-05-27 08:11:06 +00:00
|
|
|
|
2012-12-09 03:17:14 +00:00
|
|
|
if(!data || !data->have_locale)
|
|
|
|
return MSVCRT_locale->mbcinfo;
|
2008-05-27 08:11:06 +00:00
|
|
|
|
2012-12-09 03:17:14 +00:00
|
|
|
return data->mbcinfo;
|
|
|
|
}
|
2008-05-27 08:11:06 +00:00
|
|
|
|
2012-12-09 03:17:14 +00:00
|
|
|
/* INTERNAL: constructs string returned by setlocale */
|
|
|
|
static inline char* construct_lc_all(MSVCRT_pthreadlocinfo locinfo) {
|
|
|
|
static char current_lc_all[MAX_LOCALE_LENGTH];
|
2008-05-27 08:11:06 +00:00
|
|
|
|
2012-12-09 03:17:14 +00:00
|
|
|
int i;
|
2008-05-27 08:11:06 +00:00
|
|
|
|
2013-04-03 22:46:22 +00:00
|
|
|
for(i=MSVCRT_LC_MIN+1; i<MSVCRT_LC_MAX; i++) {
|
2012-12-09 03:17:14 +00:00
|
|
|
if(strcmp(locinfo->lc_category[i].locale,
|
|
|
|
locinfo->lc_category[i+1].locale))
|
|
|
|
break;
|
2008-05-27 08:11:06 +00:00
|
|
|
}
|
|
|
|
|
2013-04-03 22:46:22 +00:00
|
|
|
if(i==MSVCRT_LC_MAX)
|
|
|
|
return locinfo->lc_category[MSVCRT_LC_COLLATE].locale;
|
2008-05-27 08:11:06 +00:00
|
|
|
|
2012-12-09 03:17:14 +00:00
|
|
|
sprintf(current_lc_all,
|
|
|
|
"LC_COLLATE=%s;LC_CTYPE=%s;LC_MONETARY=%s;LC_NUMERIC=%s;LC_TIME=%s",
|
2013-04-03 22:46:22 +00:00
|
|
|
locinfo->lc_category[MSVCRT_LC_COLLATE].locale,
|
|
|
|
locinfo->lc_category[MSVCRT_LC_CTYPE].locale,
|
|
|
|
locinfo->lc_category[MSVCRT_LC_MONETARY].locale,
|
|
|
|
locinfo->lc_category[MSVCRT_LC_NUMERIC].locale,
|
|
|
|
locinfo->lc_category[MSVCRT_LC_TIME].locale);
|
2008-05-27 08:11:06 +00:00
|
|
|
|
2012-12-09 03:17:14 +00:00
|
|
|
return current_lc_all;
|
2008-05-27 08:11:06 +00:00
|
|
|
}
|
|
|
|
|
2012-12-09 03:17:14 +00:00
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* wsetlocale (MSVCRT.@)
|
2008-05-27 08:11:06 +00:00
|
|
|
*/
|
2012-12-09 03:17:14 +00:00
|
|
|
wchar_t* CDECL _wsetlocale(int category, const wchar_t* locale)
|
2008-05-27 08:11:06 +00:00
|
|
|
{
|
|
|
|
static wchar_t fake[] = {
|
|
|
|
'E','n','g','l','i','s','h','_','U','n','i','t','e','d',' ',
|
|
|
|
'S','t','a','t','e','s','.','1','2','5','2',0 };
|
2007-03-14 20:24:57 +00:00
|
|
|
|
2012-12-09 03:17:14 +00:00
|
|
|
FIXME("%d %s\n", category, debugstr_w(locale));
|
2007-03-14 20:24:57 +00:00
|
|
|
|
2008-05-27 08:11:06 +00:00
|
|
|
return fake;
|
2007-03-14 20:24:57 +00:00
|
|
|
}
|
|
|
|
|
2012-12-09 03:17:14 +00:00
|
|
|
/*********************************************************************
|
|
|
|
* _Getdays (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
char* CDECL _Getdays(void)
|
|
|
|
{
|
|
|
|
MSVCRT___lc_time_data *cur = get_locinfo()->lc_time_curr;
|
|
|
|
int i, len, size;
|
|
|
|
char *out;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
size = cur->str.names.short_mon[0]-cur->str.names.short_wday[0];
|
2013-04-03 22:46:22 +00:00
|
|
|
out = MSVCRT_malloc(size+1);
|
2012-12-09 03:17:14 +00:00
|
|
|
if(!out)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
size = 0;
|
|
|
|
for(i=0; i<7; i++) {
|
|
|
|
out[size++] = ':';
|
|
|
|
len = strlen(cur->str.names.short_wday[i]);
|
|
|
|
memcpy(&out[size], cur->str.names.short_wday[i], len);
|
|
|
|
size += len;
|
|
|
|
|
|
|
|
out[size++] = ':';
|
|
|
|
len = strlen(cur->str.names.wday[i]);
|
|
|
|
memcpy(&out[size], cur->str.names.wday[i], len);
|
|
|
|
size += len;
|
|
|
|
}
|
|
|
|
out[size] = '\0';
|
2007-03-14 20:24:57 +00:00
|
|
|
|
2012-12-09 03:17:14 +00:00
|
|
|
return out;
|
|
|
|
}
|
2007-03-14 20:24:57 +00:00
|
|
|
|
2012-12-09 03:17:14 +00:00
|
|
|
/*********************************************************************
|
|
|
|
* _Getmonths (MSVCRT.@)
|
2007-03-14 20:24:57 +00:00
|
|
|
*/
|
2012-12-09 03:17:14 +00:00
|
|
|
char* CDECL _Getmonths(void)
|
2007-03-14 20:24:57 +00:00
|
|
|
{
|
2012-12-09 03:17:14 +00:00
|
|
|
MSVCRT___lc_time_data *cur = get_locinfo()->lc_time_curr;
|
|
|
|
int i, len, size;
|
|
|
|
char *out;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
size = cur->str.names.am-cur->str.names.short_mon[0];
|
2013-04-03 22:46:22 +00:00
|
|
|
out = MSVCRT_malloc(size+1);
|
2012-12-09 03:17:14 +00:00
|
|
|
if(!out)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
size = 0;
|
|
|
|
for(i=0; i<12; i++) {
|
|
|
|
out[size++] = ':';
|
|
|
|
len = strlen(cur->str.names.short_mon[i]);
|
|
|
|
memcpy(&out[size], cur->str.names.short_mon[i], len);
|
|
|
|
size += len;
|
|
|
|
|
|
|
|
out[size++] = ':';
|
|
|
|
len = strlen(cur->str.names.mon[i]);
|
|
|
|
memcpy(&out[size], cur->str.names.mon[i], len);
|
|
|
|
size += len;
|
|
|
|
}
|
|
|
|
out[size] = '\0';
|
|
|
|
|
|
|
|
return out;
|
2007-03-14 20:24:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
2012-12-09 03:17:14 +00:00
|
|
|
* _Gettnames (MSVCRT.@)
|
2007-03-14 20:24:57 +00:00
|
|
|
*/
|
2012-12-09 03:17:14 +00:00
|
|
|
void* CDECL _Gettnames(void)
|
|
|
|
{
|
|
|
|
MSVCRT___lc_time_data *ret, *cur = get_locinfo()->lc_time_curr;
|
2013-04-03 22:46:22 +00:00
|
|
|
unsigned int i, size = sizeof(MSVCRT___lc_time_data);
|
2008-06-06 17:49:24 +00:00
|
|
|
|
2012-12-09 03:17:14 +00:00
|
|
|
TRACE("\n");
|
2008-06-06 17:49:24 +00:00
|
|
|
|
2012-12-09 03:17:14 +00:00
|
|
|
for(i=0; i<sizeof(cur->str.str)/sizeof(cur->str.str[0]); i++)
|
|
|
|
size += strlen(cur->str.str[i])+1;
|
2008-06-06 17:49:24 +00:00
|
|
|
|
2013-04-03 22:46:22 +00:00
|
|
|
ret = MSVCRT_malloc(size);
|
2012-12-09 03:17:14 +00:00
|
|
|
if(!ret)
|
|
|
|
return NULL;
|
|
|
|
memcpy(ret, cur, size);
|
2008-06-06 17:49:24 +00:00
|
|
|
|
2012-12-09 03:17:14 +00:00
|
|
|
size = 0;
|
|
|
|
for(i=0; i<sizeof(cur->str.str)/sizeof(cur->str.str[0]); i++) {
|
|
|
|
ret->str.str[i] = &ret->data[size];
|
|
|
|
size += strlen(&ret->data[size])+1;
|
2008-06-06 17:49:24 +00:00
|
|
|
}
|
|
|
|
|
2012-12-09 03:17:14 +00:00
|
|
|
return ret;
|
|
|
|
}
|
2008-06-06 17:49:24 +00:00
|
|
|
|
2012-12-09 03:17:14 +00:00
|
|
|
/*********************************************************************
|
|
|
|
* __crtLCMapStringA (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int CDECL __crtLCMapStringA(
|
|
|
|
LCID lcid, DWORD mapflags, const char* src, int srclen, char* dst,
|
|
|
|
int dstlen, unsigned int codepage, int xflag
|
|
|
|
) {
|
|
|
|
FIXME("(lcid %x, flags %x, %s(%d), %p(%d), %x, %d), partial stub!\n",
|
|
|
|
lcid,mapflags,src,srclen,dst,dstlen,codepage,xflag);
|
|
|
|
/* FIXME: A bit incorrect. But msvcrt itself just converts its
|
|
|
|
* arguments to wide strings and then calls LCMapStringW
|
|
|
|
*/
|
|
|
|
return LCMapStringA(lcid,mapflags,src,srclen,dst,dstlen);
|
|
|
|
}
|
2008-06-06 17:49:24 +00:00
|
|
|
|
2012-12-09 03:17:14 +00:00
|
|
|
/*********************************************************************
|
|
|
|
* __crtLCMapStringW (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int CDECL __crtLCMapStringW(LCID lcid, DWORD mapflags, const wchar_t *src,
|
|
|
|
int srclen, wchar_t *dst, int dstlen, unsigned int codepage, int xflag)
|
|
|
|
{
|
|
|
|
FIXME("(lcid %x, flags %x, %s(%d), %p(%d), %x, %d), partial stub!\n",
|
|
|
|
lcid, mapflags, debugstr_w(src), srclen, dst, dstlen, codepage, xflag);
|
2008-06-06 17:49:24 +00:00
|
|
|
|
2012-12-09 03:17:14 +00:00
|
|
|
return LCMapStringW(lcid, mapflags, src, srclen, dst, dstlen);
|
2007-03-14 20:24:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
2012-12-09 03:17:14 +00:00
|
|
|
* __crtCompareStringA (MSVCRT.@)
|
2007-03-14 20:24:57 +00:00
|
|
|
*/
|
2012-12-09 03:17:14 +00:00
|
|
|
int CDECL __crtCompareStringA( LCID lcid, DWORD flags, const char *src1, int len1,
|
|
|
|
const char *src2, int len2 )
|
2007-03-14 20:24:57 +00:00
|
|
|
{
|
2012-12-09 03:17:14 +00:00
|
|
|
FIXME("(lcid %x, flags %x, %s(%d), %s(%d), partial stub\n",
|
|
|
|
lcid, flags, debugstr_a(src1), len1, debugstr_a(src2), len2 );
|
|
|
|
/* FIXME: probably not entirely right */
|
|
|
|
return CompareStringA( lcid, flags, src1, len1, src2, len2 );
|
2007-03-14 20:24:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
2012-12-09 03:17:14 +00:00
|
|
|
* __crtCompareStringW (MSVCRT.@)
|
2007-03-14 20:24:57 +00:00
|
|
|
*/
|
2012-12-09 03:17:14 +00:00
|
|
|
int CDECL __crtCompareStringW( LCID lcid, DWORD flags, const wchar_t *src1, int len1,
|
|
|
|
const wchar_t *src2, int len2 )
|
2007-03-14 20:24:57 +00:00
|
|
|
{
|
2012-12-09 03:17:14 +00:00
|
|
|
FIXME("(lcid %x, flags %x, %s(%d), %s(%d), partial stub\n",
|
|
|
|
lcid, flags, debugstr_w(src1), len1, debugstr_w(src2), len2 );
|
|
|
|
/* FIXME: probably not entirely right */
|
|
|
|
return CompareStringW( lcid, flags, src1, len1, src2, len2 );
|
2007-03-14 20:24:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
2012-12-09 03:17:14 +00:00
|
|
|
* __crtGetLocaleInfoW (MSVCRT.@)
|
2007-03-14 20:24:57 +00:00
|
|
|
*/
|
2012-12-09 03:17:14 +00:00
|
|
|
int CDECL __crtGetLocaleInfoW( LCID lcid, LCTYPE type, wchar_t *buffer, int len )
|
2007-03-14 20:24:57 +00:00
|
|
|
{
|
2012-12-09 03:17:14 +00:00
|
|
|
FIXME("(lcid %x, type %x, %p(%d), partial stub\n", lcid, type, buffer, len );
|
|
|
|
/* FIXME: probably not entirely right */
|
|
|
|
return GetLocaleInfoW( lcid, type, buffer, len );
|
2007-03-14 20:24:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
2012-12-09 03:17:14 +00:00
|
|
|
* btowc(MSVCRT.@)
|
2007-03-14 20:24:57 +00:00
|
|
|
*/
|
2012-12-09 03:17:14 +00:00
|
|
|
wint_t CDECL MSVCRT_btowc(int c)
|
2007-03-14 20:24:57 +00:00
|
|
|
{
|
2012-12-09 03:17:14 +00:00
|
|
|
unsigned char letter = c;
|
|
|
|
wchar_t ret;
|
2008-12-17 10:24:13 +00:00
|
|
|
|
2012-12-09 03:17:14 +00:00
|
|
|
if(!MultiByteToWideChar(get_locinfo()->lc_handle[LC_CTYPE],
|
|
|
|
0, (LPCSTR)&letter, 1, &ret, 1))
|
|
|
|
return 0;
|
2008-12-17 10:24:13 +00:00
|
|
|
|
2012-12-09 03:17:14 +00:00
|
|
|
return ret;
|
2007-03-14 20:24:57 +00:00
|
|
|
}
|
|
|
|
|
2012-12-09 03:17:14 +00:00
|
|
|
/*********************************************************************
|
|
|
|
* __crtGetStringTypeW(MSVCRT.@)
|
|
|
|
*
|
|
|
|
* This function was accepting different number of arguments in older
|
|
|
|
* versions of msvcrt.
|
|
|
|
*/
|
|
|
|
BOOL CDECL __crtGetStringTypeW(DWORD unk, DWORD type,
|
|
|
|
wchar_t *buffer, int len, WORD *out)
|
|
|
|
{
|
|
|
|
FIXME("(unk %x, type %x, wstr %p(%d), %p) partial stub\n",
|
|
|
|
unk, type, buffer, len, out);
|
|
|
|
|
|
|
|
return GetStringTypeW(type, buffer, len, out);
|
|
|
|
}
|
2007-03-14 20:24:57 +00:00
|
|
|
|
|
|
|
/*********************************************************************
|
2012-12-09 03:17:14 +00:00
|
|
|
* localeconv (MSVCRT.@)
|
2007-03-14 20:24:57 +00:00
|
|
|
*/
|
2012-12-09 03:17:14 +00:00
|
|
|
struct lconv * CDECL localeconv(void)
|
2007-03-14 20:24:57 +00:00
|
|
|
{
|
2012-12-09 03:17:14 +00:00
|
|
|
return (struct lconv*)get_locinfo()->lconv;
|
2007-03-14 20:24:57 +00:00
|
|
|
}
|
|
|
|
|
2012-12-09 03:17:14 +00:00
|
|
|
/*********************************************************************
|
|
|
|
* __lconv_init (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int CDECL __lconv_init(void)
|
|
|
|
{
|
|
|
|
/* this is used to make chars unsigned */
|
|
|
|
charmax = 255;
|
|
|
|
return 0;
|
|
|
|
}
|
2007-03-14 20:24:57 +00:00
|
|
|
|
|
|
|
/*********************************************************************
|
2012-12-09 03:17:14 +00:00
|
|
|
* ___lc_handle_func (MSVCRT.@)
|
2007-03-14 20:24:57 +00:00
|
|
|
*/
|
2012-12-09 03:17:14 +00:00
|
|
|
LCID* CDECL ___lc_handle_func(void)
|
2007-03-14 20:24:57 +00:00
|
|
|
{
|
2012-12-09 03:17:14 +00:00
|
|
|
return MSVCRT___lc_handle;
|
2007-03-14 20:24:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
2012-12-09 03:17:14 +00:00
|
|
|
* ___lc_codepage_func (MSVCRT.@)
|
2007-03-14 20:24:57 +00:00
|
|
|
*/
|
2012-12-09 03:17:14 +00:00
|
|
|
unsigned int CDECL ___lc_codepage_func(void)
|
2007-03-14 20:24:57 +00:00
|
|
|
{
|
2012-12-13 21:13:06 +00:00
|
|
|
return __lc_codepage;
|
2007-03-14 20:24:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
2012-12-09 03:17:14 +00:00
|
|
|
* ___lc_collate_cp_func (MSVCRT.@)
|
2007-03-14 20:24:57 +00:00
|
|
|
*/
|
2012-12-09 03:17:14 +00:00
|
|
|
int CDECL ___lc_collate_cp_func(void)
|
|
|
|
{
|
|
|
|
return get_locinfo()->lc_collate_cp;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* INTERNAL: frees MSVCRT_pthreadlocinfo struct */
|
|
|
|
void free_locinfo(MSVCRT_pthreadlocinfo locinfo)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if(!locinfo)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if(InterlockedDecrement(&locinfo->refcount))
|
|
|
|
return;
|
|
|
|
|
2013-04-03 22:46:22 +00:00
|
|
|
for(i=MSVCRT_LC_MIN+1; i<=MSVCRT_LC_MAX; i++) {
|
|
|
|
MSVCRT_free(locinfo->lc_category[i].locale);
|
|
|
|
MSVCRT_free(locinfo->lc_category[i].refcount);
|
2012-12-09 03:17:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(locinfo->lconv) {
|
2013-04-03 22:46:22 +00:00
|
|
|
MSVCRT_free(locinfo->lconv->decimal_point);
|
|
|
|
MSVCRT_free(locinfo->lconv->thousands_sep);
|
|
|
|
MSVCRT_free(locinfo->lconv->grouping);
|
|
|
|
MSVCRT_free(locinfo->lconv->int_curr_symbol);
|
|
|
|
MSVCRT_free(locinfo->lconv->currency_symbol);
|
|
|
|
MSVCRT_free(locinfo->lconv->mon_decimal_point);
|
|
|
|
MSVCRT_free(locinfo->lconv->mon_thousands_sep);
|
|
|
|
MSVCRT_free(locinfo->lconv->mon_grouping);
|
|
|
|
MSVCRT_free(locinfo->lconv->positive_sign);
|
|
|
|
MSVCRT_free(locinfo->lconv->negative_sign);
|
2012-12-09 03:17:14 +00:00
|
|
|
}
|
2013-04-03 22:46:22 +00:00
|
|
|
MSVCRT_free(locinfo->lconv_intl_refcount);
|
|
|
|
MSVCRT_free(locinfo->lconv_num_refcount);
|
|
|
|
MSVCRT_free(locinfo->lconv_mon_refcount);
|
|
|
|
MSVCRT_free(locinfo->lconv);
|
2012-12-09 03:17:14 +00:00
|
|
|
|
2013-04-03 22:46:22 +00:00
|
|
|
MSVCRT_free(locinfo->ctype1_refcount);
|
|
|
|
MSVCRT_free(locinfo->ctype1);
|
2012-12-09 03:17:14 +00:00
|
|
|
|
2013-04-03 22:46:22 +00:00
|
|
|
MSVCRT_free(locinfo->pclmap);
|
|
|
|
MSVCRT_free(locinfo->pcumap);
|
2012-12-09 03:17:14 +00:00
|
|
|
|
2013-04-03 22:46:22 +00:00
|
|
|
MSVCRT_free(locinfo->lc_time_curr);
|
2012-12-09 03:17:14 +00:00
|
|
|
|
2013-04-03 22:46:22 +00:00
|
|
|
MSVCRT_free(locinfo);
|
2012-12-09 03:17:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* INTERNAL: frees MSVCRT_pthreadmbcinfo struct */
|
|
|
|
void free_mbcinfo(MSVCRT_pthreadmbcinfo mbcinfo)
|
|
|
|
{
|
|
|
|
if(!mbcinfo)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if(InterlockedDecrement(&mbcinfo->refcount))
|
|
|
|
return;
|
|
|
|
|
2013-04-03 22:46:22 +00:00
|
|
|
MSVCRT_free(mbcinfo);
|
2012-12-09 03:17:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* _get_current_locale - not exported in native msvcrt */
|
|
|
|
MSVCRT__locale_t CDECL MSVCRT__get_current_locale(void)
|
|
|
|
{
|
2013-04-03 22:46:22 +00:00
|
|
|
MSVCRT__locale_t loc = MSVCRT_malloc(sizeof(MSVCRT__locale_tstruct));
|
2012-12-09 03:17:14 +00:00
|
|
|
if(!loc)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
loc->locinfo = get_locinfo();
|
|
|
|
loc->mbcinfo = get_mbcinfo();
|
|
|
|
InterlockedIncrement(&loc->locinfo->refcount);
|
|
|
|
InterlockedIncrement(&loc->mbcinfo->refcount);
|
|
|
|
return loc;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* _free_locale - not exported in native msvcrt */
|
|
|
|
void CDECL MSVCRT__free_locale(MSVCRT__locale_t locale)
|
|
|
|
{
|
|
|
|
if (!locale)
|
|
|
|
return;
|
|
|
|
|
|
|
|
free_locinfo(locale->locinfo);
|
|
|
|
free_mbcinfo(locale->mbcinfo);
|
2013-04-03 22:46:22 +00:00
|
|
|
MSVCRT_free(locale);
|
2012-12-09 03:17:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* _create_locale - not exported in native msvcrt */
|
|
|
|
MSVCRT__locale_t CDECL MSVCRT__create_locale(int category, const char *locale)
|
|
|
|
{
|
|
|
|
static const DWORD time_data[] = {
|
|
|
|
LOCALE_SABBREVDAYNAME7, LOCALE_SABBREVDAYNAME1, LOCALE_SABBREVDAYNAME2,
|
|
|
|
LOCALE_SABBREVDAYNAME3, LOCALE_SABBREVDAYNAME4, LOCALE_SABBREVDAYNAME5,
|
|
|
|
LOCALE_SABBREVDAYNAME6,
|
|
|
|
LOCALE_SDAYNAME7, LOCALE_SDAYNAME1, LOCALE_SDAYNAME2, LOCALE_SDAYNAME3,
|
|
|
|
LOCALE_SDAYNAME4, LOCALE_SDAYNAME5, LOCALE_SDAYNAME6,
|
|
|
|
LOCALE_SABBREVMONTHNAME1, LOCALE_SABBREVMONTHNAME2, LOCALE_SABBREVMONTHNAME3,
|
|
|
|
LOCALE_SABBREVMONTHNAME4, LOCALE_SABBREVMONTHNAME5, LOCALE_SABBREVMONTHNAME6,
|
|
|
|
LOCALE_SABBREVMONTHNAME7, LOCALE_SABBREVMONTHNAME8, LOCALE_SABBREVMONTHNAME9,
|
|
|
|
LOCALE_SABBREVMONTHNAME10, LOCALE_SABBREVMONTHNAME11, LOCALE_SABBREVMONTHNAME12,
|
|
|
|
LOCALE_SMONTHNAME1, LOCALE_SMONTHNAME2, LOCALE_SMONTHNAME3, LOCALE_SMONTHNAME4,
|
|
|
|
LOCALE_SMONTHNAME5, LOCALE_SMONTHNAME6, LOCALE_SMONTHNAME7, LOCALE_SMONTHNAME8,
|
|
|
|
LOCALE_SMONTHNAME9, LOCALE_SMONTHNAME10, LOCALE_SMONTHNAME11, LOCALE_SMONTHNAME12,
|
|
|
|
LOCALE_S1159, LOCALE_S2359,
|
|
|
|
LOCALE_SSHORTDATE, LOCALE_SLONGDATE,
|
|
|
|
LOCALE_STIMEFORMAT
|
|
|
|
};
|
|
|
|
static const char collate[] = "COLLATE=";
|
|
|
|
static const char ctype[] = "CTYPE=";
|
|
|
|
static const char monetary[] = "MONETARY=";
|
|
|
|
static const char numeric[] = "NUMERIC=";
|
|
|
|
static const char time[] = "TIME=";
|
|
|
|
static const char cloc_short_date[] = "MM/dd/yy";
|
|
|
|
static const wchar_t cloc_short_dateW[] = {'M','M','/','d','d','/','y','y',0};
|
|
|
|
static const char cloc_long_date[] = "dddd, MMMM dd, yyyy";
|
|
|
|
static const wchar_t cloc_long_dateW[] = {'d','d','d','d',',',' ','M','M','M','M',' ','d','d',',',' ','y','y','y','y',0};
|
|
|
|
static const char cloc_time[] = "HH:mm:ss";
|
|
|
|
static const wchar_t cloc_timeW[] = {'H','H',':','m','m',':','s','s',0};
|
|
|
|
|
|
|
|
MSVCRT__locale_t loc;
|
|
|
|
LCID lcid[6] = { 0 }, lcid_tmp;
|
2013-04-03 22:46:22 +00:00
|
|
|
unsigned short cp[6] = { 0 };
|
2012-12-09 03:17:14 +00:00
|
|
|
char buf[256];
|
|
|
|
int i, ret, size;
|
|
|
|
|
|
|
|
TRACE("(%d %s)\n", category, locale);
|
|
|
|
|
2013-04-03 22:46:22 +00:00
|
|
|
if(category<MSVCRT_LC_MIN || category>MSVCRT_LC_MAX || !locale)
|
2012-12-09 03:17:14 +00:00
|
|
|
return NULL;
|
|
|
|
|
2013-04-03 22:46:22 +00:00
|
|
|
if(locale[0]=='C' && !locale[1]) {
|
|
|
|
lcid[0] = 0;
|
|
|
|
cp[0] = CP_ACP;
|
|
|
|
} else if(!locale[0]) {
|
2012-12-09 03:17:14 +00:00
|
|
|
lcid[0] = GetSystemDefaultLCID();
|
2013-04-03 22:46:22 +00:00
|
|
|
GetLocaleInfoA(lcid[0], LOCALE_IDEFAULTANSICODEPAGE
|
|
|
|
|LOCALE_NOUSEROVERRIDE, buf, sizeof(buf));
|
|
|
|
cp[0] = atoi(buf);
|
|
|
|
|
|
|
|
for(i=1; i<6; i++) {
|
|
|
|
lcid[i] = lcid[0];
|
|
|
|
cp[i] = cp[0];
|
|
|
|
}
|
|
|
|
} else if (locale[0] == 'L' && locale[1] == 'C' && locale[2] == '_') {
|
2012-12-09 03:17:14 +00:00
|
|
|
const char *p;
|
|
|
|
|
|
|
|
while(1) {
|
|
|
|
locale += 3; /* LC_ */
|
|
|
|
if(!memcmp(locale, collate, sizeof(collate)-1)) {
|
2013-04-03 22:46:22 +00:00
|
|
|
i = MSVCRT_LC_COLLATE;
|
2012-12-09 03:17:14 +00:00
|
|
|
locale += sizeof(collate)-1;
|
|
|
|
} else if(!memcmp(locale, ctype, sizeof(ctype)-1)) {
|
2013-04-03 22:46:22 +00:00
|
|
|
i = MSVCRT_LC_CTYPE;
|
2012-12-09 03:17:14 +00:00
|
|
|
locale += sizeof(ctype)-1;
|
|
|
|
} else if(!memcmp(locale, monetary, sizeof(monetary)-1)) {
|
2013-04-03 22:46:22 +00:00
|
|
|
i = MSVCRT_LC_MONETARY;
|
2012-12-09 03:17:14 +00:00
|
|
|
locale += sizeof(monetary)-1;
|
|
|
|
} else if(!memcmp(locale, numeric, sizeof(numeric)-1)) {
|
2013-04-03 22:46:22 +00:00
|
|
|
i = MSVCRT_LC_NUMERIC;
|
2012-12-09 03:17:14 +00:00
|
|
|
locale += sizeof(numeric)-1;
|
|
|
|
} else if(!memcmp(locale, time, sizeof(time)-1)) {
|
2013-04-03 22:46:22 +00:00
|
|
|
i = MSVCRT_LC_TIME;
|
2012-12-09 03:17:14 +00:00
|
|
|
locale += sizeof(time)-1;
|
|
|
|
} else
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
p = strchr(locale, ';');
|
2013-04-03 22:46:22 +00:00
|
|
|
if(locale[0]=='C' && (locale[1]==';' || locale[1]=='\0')) {
|
2012-12-09 03:17:14 +00:00
|
|
|
lcid[i] = 0;
|
2013-04-03 22:46:22 +00:00
|
|
|
cp[i] = CP_ACP;
|
|
|
|
} else if(p) {
|
2012-12-09 03:17:14 +00:00
|
|
|
memcpy(buf, locale, p-locale);
|
|
|
|
buf[p-locale] = '\0';
|
2013-04-03 22:46:22 +00:00
|
|
|
lcid[i] = MSVCRT_locale_to_LCID(buf, &cp[i]);
|
2012-12-09 03:17:14 +00:00
|
|
|
} else
|
2013-04-03 22:46:22 +00:00
|
|
|
lcid[i] = MSVCRT_locale_to_LCID(locale, &cp[i]);
|
2012-12-09 03:17:14 +00:00
|
|
|
|
|
|
|
if(lcid[i] == -1)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if(!p || *(p+1)!='L' || *(p+2)!='C' || *(p+3)!='_')
|
|
|
|
break;
|
|
|
|
|
|
|
|
locale = p+1;
|
|
|
|
}
|
|
|
|
} else {
|
2013-04-03 22:46:22 +00:00
|
|
|
lcid[0] = MSVCRT_locale_to_LCID(locale, &cp[0]);
|
2012-12-09 03:17:14 +00:00
|
|
|
if(lcid[0] == -1)
|
|
|
|
return NULL;
|
|
|
|
|
2013-04-03 22:46:22 +00:00
|
|
|
for(i=1; i<6; i++) {
|
2012-12-09 03:17:14 +00:00
|
|
|
lcid[i] = lcid[0];
|
2013-04-03 22:46:22 +00:00
|
|
|
cp[i] = cp[0];
|
|
|
|
}
|
2012-12-09 03:17:14 +00:00
|
|
|
}
|
|
|
|
|
2013-04-03 22:46:22 +00:00
|
|
|
loc = MSVCRT_malloc(sizeof(MSVCRT__locale_tstruct));
|
2012-12-09 03:17:14 +00:00
|
|
|
if(!loc)
|
|
|
|
return NULL;
|
|
|
|
|
2013-04-03 22:46:22 +00:00
|
|
|
loc->locinfo = MSVCRT_malloc(sizeof(MSVCRT_threadlocinfo));
|
2012-12-09 03:17:14 +00:00
|
|
|
if(!loc->locinfo) {
|
2013-04-03 22:46:22 +00:00
|
|
|
MSVCRT_free(loc);
|
2012-12-09 03:17:14 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-04-03 22:46:22 +00:00
|
|
|
loc->mbcinfo = MSVCRT_malloc(sizeof(MSVCRT_threadmbcinfo));
|
2012-12-09 03:17:14 +00:00
|
|
|
if(!loc->mbcinfo) {
|
2013-04-03 22:46:22 +00:00
|
|
|
MSVCRT_free(loc->locinfo);
|
|
|
|
MSVCRT_free(loc);
|
2012-12-09 03:17:14 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
memset(loc->locinfo, 0, sizeof(MSVCRT_threadlocinfo));
|
|
|
|
loc->locinfo->refcount = 1;
|
|
|
|
loc->mbcinfo->refcount = 1;
|
|
|
|
|
2013-04-03 22:46:22 +00:00
|
|
|
loc->locinfo->lconv = MSVCRT_malloc(sizeof(struct MSVCRT_lconv));
|
2012-12-09 03:17:14 +00:00
|
|
|
if(!loc->locinfo->lconv) {
|
|
|
|
MSVCRT__free_locale(loc);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
memset(loc->locinfo->lconv, 0, sizeof(struct MSVCRT_lconv));
|
|
|
|
|
2013-04-03 22:46:22 +00:00
|
|
|
loc->locinfo->pclmap = MSVCRT_malloc(sizeof(char[256]));
|
|
|
|
loc->locinfo->pcumap = MSVCRT_malloc(sizeof(char[256]));
|
2012-12-09 03:17:14 +00:00
|
|
|
if(!loc->locinfo->pclmap || !loc->locinfo->pcumap) {
|
|
|
|
MSVCRT__free_locale(loc);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-04-03 22:46:22 +00:00
|
|
|
if(lcid[MSVCRT_LC_COLLATE] && (category==MSVCRT_LC_ALL || category==MSVCRT_LC_COLLATE)) {
|
|
|
|
if(update_threadlocinfo_category(lcid[MSVCRT_LC_COLLATE], cp[MSVCRT_LC_COLLATE], loc, MSVCRT_LC_COLLATE)) {
|
2012-12-09 03:17:14 +00:00
|
|
|
MSVCRT__free_locale(loc);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-04-03 22:46:22 +00:00
|
|
|
loc->locinfo->lc_collate_cp = loc->locinfo->lc_id[MSVCRT_LC_COLLATE].wCodePage;
|
2012-12-09 03:17:14 +00:00
|
|
|
} else
|
|
|
|
loc->locinfo->lc_category[LC_COLLATE].locale = _strdup("C");
|
|
|
|
|
2013-04-03 22:46:22 +00:00
|
|
|
if(lcid[MSVCRT_LC_CTYPE] && (category==MSVCRT_LC_ALL || category==MSVCRT_LC_CTYPE)) {
|
|
|
|
CPINFO cp_info;
|
2012-12-09 03:17:14 +00:00
|
|
|
int j;
|
|
|
|
|
2013-04-03 22:46:22 +00:00
|
|
|
if(update_threadlocinfo_category(lcid[MSVCRT_LC_CTYPE], cp[MSVCRT_LC_CTYPE], loc, MSVCRT_LC_CTYPE)) {
|
2012-12-09 03:17:14 +00:00
|
|
|
MSVCRT__free_locale(loc);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-04-03 22:46:22 +00:00
|
|
|
loc->locinfo->lc_codepage = loc->locinfo->lc_id[MSVCRT_LC_CTYPE].wCodePage;
|
2012-12-09 03:17:14 +00:00
|
|
|
loc->locinfo->lc_clike = 1;
|
2013-04-03 22:46:22 +00:00
|
|
|
if(!GetCPInfo(loc->locinfo->lc_codepage, &cp_info)) {
|
2012-12-09 03:17:14 +00:00
|
|
|
MSVCRT__free_locale(loc);
|
|
|
|
return NULL;
|
|
|
|
}
|
2013-04-03 22:46:22 +00:00
|
|
|
loc->locinfo->mb_cur_max = cp_info.MaxCharSize;
|
2012-12-09 03:17:14 +00:00
|
|
|
|
2013-04-03 22:46:22 +00:00
|
|
|
loc->locinfo->ctype1_refcount = MSVCRT_malloc(sizeof(int));
|
|
|
|
loc->locinfo->ctype1 = MSVCRT_malloc(sizeof(short[257]));
|
2012-12-09 03:17:14 +00:00
|
|
|
if(!loc->locinfo->ctype1_refcount || !loc->locinfo->ctype1) {
|
|
|
|
MSVCRT__free_locale(loc);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
*loc->locinfo->ctype1_refcount = 1;
|
|
|
|
loc->locinfo->ctype1[0] = 0;
|
|
|
|
loc->locinfo->pctype = loc->locinfo->ctype1+1;
|
|
|
|
|
|
|
|
buf[1] = buf[2] = '\0';
|
|
|
|
for(i=1; i<257; i++) {
|
|
|
|
buf[0] = i-1;
|
|
|
|
|
|
|
|
/* builtin GetStringTypeA doesn't set output to 0 on invalid input */
|
|
|
|
loc->locinfo->ctype1[i] = 0;
|
|
|
|
|
2013-04-03 22:46:22 +00:00
|
|
|
GetStringTypeA(lcid[MSVCRT_LC_CTYPE], CT_CTYPE1, buf,
|
2012-12-09 03:17:14 +00:00
|
|
|
1, loc->locinfo->ctype1+i);
|
|
|
|
}
|
|
|
|
|
2013-04-03 22:46:22 +00:00
|
|
|
for(i=0; cp_info.LeadByte[i+1]!=0; i+=2)
|
|
|
|
for(j=cp_info.LeadByte[i]; j<=cp_info.LeadByte[i+1]; j++)
|
2012-12-09 03:17:14 +00:00
|
|
|
loc->locinfo->ctype1[j+1] |= _LEADBYTE;
|
|
|
|
} else {
|
|
|
|
loc->locinfo->lc_clike = 1;
|
|
|
|
loc->locinfo->mb_cur_max = 1;
|
|
|
|
loc->locinfo->pctype = _ctype+1;
|
|
|
|
loc->locinfo->lc_category[LC_CTYPE].locale = _strdup("C");
|
|
|
|
}
|
|
|
|
|
|
|
|
for(i=0; i<256; i++) {
|
|
|
|
if(loc->locinfo->pctype[i] & _LEADBYTE)
|
|
|
|
buf[i] = ' ';
|
|
|
|
else
|
|
|
|
buf[i] = i;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-04-03 22:46:22 +00:00
|
|
|
if(lcid[MSVCRT_LC_CTYPE]) {
|
|
|
|
LCMapStringA(lcid[MSVCRT_LC_CTYPE], LCMAP_LOWERCASE, buf, 256,
|
2012-12-09 03:17:14 +00:00
|
|
|
(char*)loc->locinfo->pclmap, 256);
|
2013-04-03 22:46:22 +00:00
|
|
|
LCMapStringA(lcid[MSVCRT_LC_CTYPE], LCMAP_UPPERCASE, buf, 256,
|
2012-12-09 03:17:14 +00:00
|
|
|
(char*)loc->locinfo->pcumap, 256);
|
|
|
|
} else {
|
|
|
|
for(i=0; i<256; i++) {
|
|
|
|
loc->locinfo->pclmap[i] = (i>='A' && i<='Z' ? i-'A'+'a' : i);
|
|
|
|
loc->locinfo->pcumap[i] = (i>='a' && i<='z' ? i-'a'+'A' : i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-03 22:46:22 +00:00
|
|
|
_setmbcp_l(loc->locinfo->lc_id[MSVCRT_LC_CTYPE].wCodePage, lcid[MSVCRT_LC_CTYPE], loc->mbcinfo);
|
2012-12-09 03:17:14 +00:00
|
|
|
|
2013-04-03 22:46:22 +00:00
|
|
|
if(lcid[MSVCRT_LC_MONETARY] && (category==MSVCRT_LC_ALL || category==MSVCRT_LC_MONETARY)) {
|
|
|
|
if(update_threadlocinfo_category(lcid[MSVCRT_LC_MONETARY], cp[MSVCRT_LC_MONETARY], loc, MSVCRT_LC_MONETARY)) {
|
2012-12-09 03:17:14 +00:00
|
|
|
MSVCRT__free_locale(loc);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-04-03 22:46:22 +00:00
|
|
|
loc->locinfo->lconv_intl_refcount = MSVCRT_malloc(sizeof(int));
|
|
|
|
loc->locinfo->lconv_mon_refcount = MSVCRT_malloc(sizeof(int));
|
2012-12-09 03:17:14 +00:00
|
|
|
if(!loc->locinfo->lconv_intl_refcount || !loc->locinfo->lconv_mon_refcount) {
|
|
|
|
MSVCRT__free_locale(loc);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
*loc->locinfo->lconv_intl_refcount = 1;
|
|
|
|
*loc->locinfo->lconv_mon_refcount = 1;
|
|
|
|
|
2013-04-03 22:46:22 +00:00
|
|
|
i = GetLocaleInfoA(lcid[MSVCRT_LC_MONETARY], LOCALE_SINTLSYMBOL
|
2012-12-09 03:17:14 +00:00
|
|
|
|LOCALE_NOUSEROVERRIDE, buf, 256);
|
2013-04-03 22:46:22 +00:00
|
|
|
if(i && (loc->locinfo->lconv->int_curr_symbol = MSVCRT_malloc(i)))
|
2012-12-09 03:17:14 +00:00
|
|
|
memcpy(loc->locinfo->lconv->int_curr_symbol, buf, i);
|
|
|
|
else {
|
|
|
|
MSVCRT__free_locale(loc);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-04-03 22:46:22 +00:00
|
|
|
i = GetLocaleInfoA(lcid[MSVCRT_LC_MONETARY], LOCALE_SCURRENCY
|
2012-12-09 03:17:14 +00:00
|
|
|
|LOCALE_NOUSEROVERRIDE, buf, 256);
|
2013-04-03 22:46:22 +00:00
|
|
|
if(i && (loc->locinfo->lconv->currency_symbol = MSVCRT_malloc(i)))
|
2012-12-09 03:17:14 +00:00
|
|
|
memcpy(loc->locinfo->lconv->currency_symbol, buf, i);
|
|
|
|
else {
|
|
|
|
MSVCRT__free_locale(loc);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-04-03 22:46:22 +00:00
|
|
|
i = GetLocaleInfoA(lcid[MSVCRT_LC_MONETARY], LOCALE_SMONDECIMALSEP
|
2012-12-09 03:17:14 +00:00
|
|
|
|LOCALE_NOUSEROVERRIDE, buf, 256);
|
2013-04-03 22:46:22 +00:00
|
|
|
if(i && (loc->locinfo->lconv->mon_decimal_point = MSVCRT_malloc(i)))
|
2012-12-09 03:17:14 +00:00
|
|
|
memcpy(loc->locinfo->lconv->mon_decimal_point, buf, i);
|
|
|
|
else {
|
|
|
|
MSVCRT__free_locale(loc);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-04-03 22:46:22 +00:00
|
|
|
i = GetLocaleInfoA(lcid[MSVCRT_LC_MONETARY], LOCALE_SMONTHOUSANDSEP
|
2012-12-09 03:17:14 +00:00
|
|
|
|LOCALE_NOUSEROVERRIDE, buf, 256);
|
2013-04-03 22:46:22 +00:00
|
|
|
if(i && (loc->locinfo->lconv->mon_thousands_sep = MSVCRT_malloc(i)))
|
2012-12-09 03:17:14 +00:00
|
|
|
memcpy(loc->locinfo->lconv->mon_thousands_sep, buf, i);
|
|
|
|
else {
|
|
|
|
MSVCRT__free_locale(loc);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-04-03 22:46:22 +00:00
|
|
|
i = GetLocaleInfoA(lcid[MSVCRT_LC_MONETARY], LOCALE_SMONGROUPING
|
2012-12-09 03:17:14 +00:00
|
|
|
|LOCALE_NOUSEROVERRIDE, buf, 256);
|
|
|
|
if(i>1)
|
|
|
|
i = i/2 + (buf[i-2]=='0'?0:1);
|
2013-04-03 22:46:22 +00:00
|
|
|
if(i && (loc->locinfo->lconv->mon_grouping = MSVCRT_malloc(i))) {
|
2012-12-09 03:17:14 +00:00
|
|
|
for(i=0; buf[i+1]==';'; i+=2)
|
|
|
|
loc->locinfo->lconv->mon_grouping[i/2] = buf[i]-'0';
|
|
|
|
loc->locinfo->lconv->mon_grouping[i/2] = buf[i]-'0';
|
|
|
|
if(buf[i] != '0')
|
|
|
|
loc->locinfo->lconv->mon_grouping[i/2+1] = 127;
|
|
|
|
} else {
|
|
|
|
MSVCRT__free_locale(loc);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-04-03 22:46:22 +00:00
|
|
|
i = GetLocaleInfoA(lcid[MSVCRT_LC_MONETARY], LOCALE_SPOSITIVESIGN
|
2012-12-09 03:17:14 +00:00
|
|
|
|LOCALE_NOUSEROVERRIDE, buf, 256);
|
2013-04-03 22:46:22 +00:00
|
|
|
if(i && (loc->locinfo->lconv->positive_sign = MSVCRT_malloc(i)))
|
2012-12-09 03:17:14 +00:00
|
|
|
memcpy(loc->locinfo->lconv->positive_sign, buf, i);
|
|
|
|
else {
|
|
|
|
MSVCRT__free_locale(loc);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-04-03 22:46:22 +00:00
|
|
|
i = GetLocaleInfoA(lcid[MSVCRT_LC_MONETARY], LOCALE_SNEGATIVESIGN
|
2012-12-09 03:17:14 +00:00
|
|
|
|LOCALE_NOUSEROVERRIDE, buf, 256);
|
2013-04-03 22:46:22 +00:00
|
|
|
if(i && (loc->locinfo->lconv->negative_sign = MSVCRT_malloc(i)))
|
2012-12-09 03:17:14 +00:00
|
|
|
memcpy(loc->locinfo->lconv->negative_sign, buf, i);
|
|
|
|
else {
|
|
|
|
MSVCRT__free_locale(loc);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-04-03 22:46:22 +00:00
|
|
|
if(GetLocaleInfoA(lcid[MSVCRT_LC_MONETARY], LOCALE_IINTLCURRDIGITS
|
2012-12-09 03:17:14 +00:00
|
|
|
|LOCALE_NOUSEROVERRIDE, buf, 256))
|
|
|
|
loc->locinfo->lconv->int_frac_digits = atoi(buf);
|
|
|
|
else {
|
|
|
|
MSVCRT__free_locale(loc);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-04-03 22:46:22 +00:00
|
|
|
if(GetLocaleInfoA(lcid[MSVCRT_LC_MONETARY], LOCALE_ICURRDIGITS
|
2012-12-09 03:17:14 +00:00
|
|
|
|LOCALE_NOUSEROVERRIDE, buf, 256))
|
|
|
|
loc->locinfo->lconv->frac_digits = atoi(buf);
|
|
|
|
else {
|
|
|
|
MSVCRT__free_locale(loc);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-04-03 22:46:22 +00:00
|
|
|
if(GetLocaleInfoA(lcid[MSVCRT_LC_MONETARY], LOCALE_IPOSSYMPRECEDES
|
2012-12-09 03:17:14 +00:00
|
|
|
|LOCALE_NOUSEROVERRIDE, buf, 256))
|
|
|
|
loc->locinfo->lconv->p_cs_precedes = atoi(buf);
|
|
|
|
else {
|
|
|
|
MSVCRT__free_locale(loc);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-04-03 22:46:22 +00:00
|
|
|
if(GetLocaleInfoA(lcid[MSVCRT_LC_MONETARY], LOCALE_IPOSSEPBYSPACE
|
2012-12-09 03:17:14 +00:00
|
|
|
|LOCALE_NOUSEROVERRIDE, buf, 256))
|
|
|
|
loc->locinfo->lconv->p_sep_by_space = atoi(buf);
|
|
|
|
else {
|
|
|
|
MSVCRT__free_locale(loc);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-04-03 22:46:22 +00:00
|
|
|
if(GetLocaleInfoA(lcid[MSVCRT_LC_MONETARY], LOCALE_INEGSYMPRECEDES
|
2012-12-09 03:17:14 +00:00
|
|
|
|LOCALE_NOUSEROVERRIDE, buf, 256))
|
|
|
|
loc->locinfo->lconv->n_cs_precedes = atoi(buf);
|
|
|
|
else {
|
|
|
|
MSVCRT__free_locale(loc);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-04-03 22:46:22 +00:00
|
|
|
if(GetLocaleInfoA(lcid[MSVCRT_LC_MONETARY], LOCALE_INEGSEPBYSPACE
|
2012-12-09 03:17:14 +00:00
|
|
|
|LOCALE_NOUSEROVERRIDE, buf, 256))
|
|
|
|
loc->locinfo->lconv->n_sep_by_space = atoi(buf);
|
|
|
|
else {
|
|
|
|
MSVCRT__free_locale(loc);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-04-03 22:46:22 +00:00
|
|
|
if(GetLocaleInfoA(lcid[MSVCRT_LC_MONETARY], LOCALE_IPOSSIGNPOSN
|
2012-12-09 03:17:14 +00:00
|
|
|
|LOCALE_NOUSEROVERRIDE, buf, 256))
|
|
|
|
loc->locinfo->lconv->p_sign_posn = atoi(buf);
|
|
|
|
else {
|
|
|
|
MSVCRT__free_locale(loc);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-04-03 22:46:22 +00:00
|
|
|
if(GetLocaleInfoA(lcid[MSVCRT_LC_MONETARY], LOCALE_INEGSIGNPOSN
|
2012-12-09 03:17:14 +00:00
|
|
|
|LOCALE_NOUSEROVERRIDE, buf, 256))
|
|
|
|
loc->locinfo->lconv->n_sign_posn = atoi(buf);
|
|
|
|
else {
|
|
|
|
MSVCRT__free_locale(loc);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
} else {
|
2013-04-03 22:46:22 +00:00
|
|
|
loc->locinfo->lconv->int_curr_symbol = MSVCRT_malloc(sizeof(char));
|
|
|
|
loc->locinfo->lconv->currency_symbol = MSVCRT_malloc(sizeof(char));
|
|
|
|
loc->locinfo->lconv->mon_decimal_point = MSVCRT_malloc(sizeof(char));
|
|
|
|
loc->locinfo->lconv->mon_thousands_sep = MSVCRT_malloc(sizeof(char));
|
|
|
|
loc->locinfo->lconv->mon_grouping = MSVCRT_malloc(sizeof(char));
|
|
|
|
loc->locinfo->lconv->positive_sign = MSVCRT_malloc(sizeof(char));
|
|
|
|
loc->locinfo->lconv->negative_sign = MSVCRT_malloc(sizeof(char));
|
2012-12-09 03:17:14 +00:00
|
|
|
|
|
|
|
if(!loc->locinfo->lconv->int_curr_symbol || !loc->locinfo->lconv->currency_symbol
|
|
|
|
|| !loc->locinfo->lconv->mon_decimal_point || !loc->locinfo->lconv->mon_thousands_sep
|
|
|
|
|| !loc->locinfo->lconv->mon_grouping || !loc->locinfo->lconv->positive_sign
|
|
|
|
|| !loc->locinfo->lconv->negative_sign) {
|
|
|
|
MSVCRT__free_locale(loc);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
loc->locinfo->lconv->int_curr_symbol[0] = '\0';
|
|
|
|
loc->locinfo->lconv->currency_symbol[0] = '\0';
|
|
|
|
loc->locinfo->lconv->mon_decimal_point[0] = '\0';
|
|
|
|
loc->locinfo->lconv->mon_thousands_sep[0] = '\0';
|
|
|
|
loc->locinfo->lconv->mon_grouping[0] = '\0';
|
|
|
|
loc->locinfo->lconv->positive_sign[0] = '\0';
|
|
|
|
loc->locinfo->lconv->negative_sign[0] = '\0';
|
|
|
|
loc->locinfo->lconv->int_frac_digits = 127;
|
|
|
|
loc->locinfo->lconv->frac_digits = 127;
|
|
|
|
loc->locinfo->lconv->p_cs_precedes = 127;
|
|
|
|
loc->locinfo->lconv->p_sep_by_space = 127;
|
|
|
|
loc->locinfo->lconv->n_cs_precedes = 127;
|
|
|
|
loc->locinfo->lconv->n_sep_by_space = 127;
|
|
|
|
loc->locinfo->lconv->p_sign_posn = 127;
|
|
|
|
loc->locinfo->lconv->n_sign_posn = 127;
|
|
|
|
|
|
|
|
loc->locinfo->lc_category[LC_MONETARY].locale = _strdup("C");
|
|
|
|
}
|
|
|
|
|
2013-04-03 22:46:22 +00:00
|
|
|
if(lcid[MSVCRT_LC_NUMERIC] && (category==MSVCRT_LC_ALL || category==MSVCRT_LC_NUMERIC)) {
|
|
|
|
if(update_threadlocinfo_category(lcid[MSVCRT_LC_NUMERIC], cp[MSVCRT_LC_NUMERIC], loc, MSVCRT_LC_NUMERIC)) {
|
2012-12-09 03:17:14 +00:00
|
|
|
MSVCRT__free_locale(loc);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!loc->locinfo->lconv_intl_refcount)
|
2013-04-03 22:46:22 +00:00
|
|
|
loc->locinfo->lconv_intl_refcount = MSVCRT_malloc(sizeof(int));
|
|
|
|
loc->locinfo->lconv_num_refcount = MSVCRT_malloc(sizeof(int));
|
2012-12-09 03:17:14 +00:00
|
|
|
if(!loc->locinfo->lconv_intl_refcount || !loc->locinfo->lconv_num_refcount) {
|
|
|
|
MSVCRT__free_locale(loc);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
*loc->locinfo->lconv_intl_refcount = 1;
|
|
|
|
*loc->locinfo->lconv_num_refcount = 1;
|
|
|
|
|
2013-04-03 22:46:22 +00:00
|
|
|
i = GetLocaleInfoA(lcid[MSVCRT_LC_NUMERIC], LOCALE_SDECIMAL
|
2012-12-09 03:17:14 +00:00
|
|
|
|LOCALE_NOUSEROVERRIDE, buf, 256);
|
2013-04-03 22:46:22 +00:00
|
|
|
if(i && (loc->locinfo->lconv->decimal_point = MSVCRT_malloc(i)))
|
2012-12-09 03:17:14 +00:00
|
|
|
memcpy(loc->locinfo->lconv->decimal_point, buf, i);
|
|
|
|
else {
|
|
|
|
MSVCRT__free_locale(loc);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-04-03 22:46:22 +00:00
|
|
|
i = GetLocaleInfoA(lcid[MSVCRT_LC_NUMERIC], LOCALE_STHOUSAND
|
2012-12-09 03:17:14 +00:00
|
|
|
|LOCALE_NOUSEROVERRIDE, buf, 256);
|
2013-04-03 22:46:22 +00:00
|
|
|
if(i && (loc->locinfo->lconv->thousands_sep = MSVCRT_malloc(i)))
|
2012-12-09 03:17:14 +00:00
|
|
|
memcpy(loc->locinfo->lconv->thousands_sep, buf, i);
|
|
|
|
else {
|
|
|
|
MSVCRT__free_locale(loc);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-04-03 22:46:22 +00:00
|
|
|
i = GetLocaleInfoA(lcid[MSVCRT_LC_NUMERIC], LOCALE_SGROUPING
|
2012-12-09 03:17:14 +00:00
|
|
|
|LOCALE_NOUSEROVERRIDE, buf, 256);
|
|
|
|
if(i>1)
|
|
|
|
i = i/2 + (buf[i-2]=='0'?0:1);
|
2013-04-03 22:46:22 +00:00
|
|
|
if(i && (loc->locinfo->lconv->grouping = MSVCRT_malloc(i))) {
|
2012-12-09 03:17:14 +00:00
|
|
|
for(i=0; buf[i+1]==';'; i+=2)
|
|
|
|
loc->locinfo->lconv->grouping[i/2] = buf[i]-'0';
|
|
|
|
loc->locinfo->lconv->grouping[i/2] = buf[i]-'0';
|
|
|
|
if(buf[i] != '0')
|
|
|
|
loc->locinfo->lconv->grouping[i/2+1] = 127;
|
|
|
|
} else {
|
|
|
|
MSVCRT__free_locale(loc);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
} else {
|
2013-04-03 22:46:22 +00:00
|
|
|
loc->locinfo->lconv->decimal_point = MSVCRT_malloc(sizeof(char[2]));
|
|
|
|
loc->locinfo->lconv->thousands_sep = MSVCRT_malloc(sizeof(char));
|
|
|
|
loc->locinfo->lconv->grouping = MSVCRT_malloc(sizeof(char));
|
2012-12-09 03:17:14 +00:00
|
|
|
if(!loc->locinfo->lconv->decimal_point || !loc->locinfo->lconv->thousands_sep
|
|
|
|
|| !loc->locinfo->lconv->grouping) {
|
|
|
|
MSVCRT__free_locale(loc);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
loc->locinfo->lconv->decimal_point[0] = '.';
|
|
|
|
loc->locinfo->lconv->decimal_point[1] = '\0';
|
|
|
|
loc->locinfo->lconv->thousands_sep[0] = '\0';
|
|
|
|
loc->locinfo->lconv->grouping[0] = '\0';
|
|
|
|
|
|
|
|
loc->locinfo->lc_category[LC_NUMERIC].locale = _strdup("C");
|
|
|
|
}
|
|
|
|
|
2013-04-03 22:46:22 +00:00
|
|
|
if(lcid[MSVCRT_LC_TIME] && (category==MSVCRT_LC_ALL || category==MSVCRT_LC_TIME)) {
|
|
|
|
if(update_threadlocinfo_category(lcid[MSVCRT_LC_TIME], cp[MSVCRT_LC_TIME], loc, MSVCRT_LC_TIME)) {
|
2012-12-09 03:17:14 +00:00
|
|
|
MSVCRT__free_locale(loc);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
loc->locinfo->lc_category[LC_TIME].locale = _strdup("C");
|
|
|
|
|
|
|
|
size = sizeof(MSVCRT___lc_time_data);
|
2013-04-03 22:46:22 +00:00
|
|
|
lcid_tmp = lcid[MSVCRT_LC_TIME] ? lcid[MSVCRT_LC_TIME] : MAKELCID(LANG_ENGLISH, SORT_DEFAULT);
|
2012-12-09 03:17:14 +00:00
|
|
|
for(i=0; i<sizeof(time_data)/sizeof(time_data[0]); i++) {
|
2013-04-03 22:46:22 +00:00
|
|
|
if(time_data[i]==LOCALE_SSHORTDATE && !lcid[MSVCRT_LC_TIME]) {
|
2012-12-09 03:17:14 +00:00
|
|
|
size += sizeof(cloc_short_date) + sizeof(cloc_short_dateW);
|
2013-05-09 20:46:54 +00:00
|
|
|
}else if(time_data[i]==LOCALE_SLONGDATE && !lcid[MSVCRT_LC_TIME]) {
|
2012-12-09 03:17:14 +00:00
|
|
|
size += sizeof(cloc_long_date) + sizeof(cloc_long_dateW);
|
|
|
|
}else {
|
|
|
|
ret = GetLocaleInfoA(lcid_tmp, time_data[i]
|
|
|
|
|LOCALE_NOUSEROVERRIDE, NULL, 0);
|
|
|
|
if(!ret) {
|
|
|
|
MSVCRT__free_locale(loc);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
size += ret;
|
|
|
|
|
|
|
|
ret = GetLocaleInfoW(lcid_tmp, time_data[i]
|
|
|
|
|LOCALE_NOUSEROVERRIDE, NULL, 0);
|
|
|
|
if(!ret) {
|
|
|
|
MSVCRT__free_locale(loc);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
size += ret*sizeof(wchar_t);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-03 22:46:22 +00:00
|
|
|
loc->locinfo->lc_time_curr = MSVCRT_malloc(size);
|
2012-12-09 03:17:14 +00:00
|
|
|
if(!loc->locinfo->lc_time_curr) {
|
|
|
|
MSVCRT__free_locale(loc);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
for(i=0; i<sizeof(time_data)/sizeof(time_data[0]); i++) {
|
|
|
|
loc->locinfo->lc_time_curr->str.str[i] = &loc->locinfo->lc_time_curr->data[ret];
|
2013-04-03 22:46:22 +00:00
|
|
|
if(time_data[i]==LOCALE_SSHORTDATE && !lcid[MSVCRT_LC_TIME]) {
|
2012-12-09 03:17:14 +00:00
|
|
|
memcpy(&loc->locinfo->lc_time_curr->data[ret], cloc_short_date, sizeof(cloc_short_date));
|
|
|
|
ret += sizeof(cloc_short_date);
|
2013-05-09 20:46:54 +00:00
|
|
|
}else if(time_data[i]==LOCALE_SLONGDATE && !lcid[MSVCRT_LC_TIME]) {
|
2012-12-09 03:17:14 +00:00
|
|
|
memcpy(&loc->locinfo->lc_time_curr->data[ret], cloc_long_date, sizeof(cloc_long_date));
|
|
|
|
ret += sizeof(cloc_long_date);
|
2013-04-03 22:46:22 +00:00
|
|
|
}else if(time_data[i]==LOCALE_STIMEFORMAT && !lcid[MSVCRT_LC_TIME]) {
|
2012-12-09 03:17:14 +00:00
|
|
|
memcpy(&loc->locinfo->lc_time_curr->data[ret], cloc_time, sizeof(cloc_time));
|
|
|
|
ret += sizeof(cloc_time);
|
|
|
|
}else {
|
|
|
|
ret += GetLocaleInfoA(lcid_tmp, time_data[i]|LOCALE_NOUSEROVERRIDE,
|
|
|
|
&loc->locinfo->lc_time_curr->data[ret], size-ret);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for(i=0; i<sizeof(time_data)/sizeof(time_data[0]); i++) {
|
|
|
|
loc->locinfo->lc_time_curr->wstr[i] = (wchar_t*)&loc->locinfo->lc_time_curr->data[ret];
|
2013-04-03 22:46:22 +00:00
|
|
|
if(time_data[i]==LOCALE_SSHORTDATE && !lcid[MSVCRT_LC_TIME]) {
|
2012-12-09 03:17:14 +00:00
|
|
|
memcpy(&loc->locinfo->lc_time_curr->data[ret], cloc_short_dateW, sizeof(cloc_short_dateW));
|
|
|
|
ret += sizeof(cloc_short_dateW);
|
2013-05-09 20:46:54 +00:00
|
|
|
}else if(time_data[i]==LOCALE_SLONGDATE && !lcid[MSVCRT_LC_TIME]) {
|
2012-12-09 03:17:14 +00:00
|
|
|
memcpy(&loc->locinfo->lc_time_curr->data[ret], cloc_long_dateW, sizeof(cloc_long_dateW));
|
|
|
|
ret += sizeof(cloc_long_dateW);
|
2013-05-09 20:46:54 +00:00
|
|
|
}else if(time_data[i]==LOCALE_STIMEFORMAT && !lcid[MSVCRT_LC_TIME]) { memcpy(&loc->locinfo->lc_time_curr->data[ret], cloc_timeW, sizeof(cloc_timeW));
|
2012-12-09 03:17:14 +00:00
|
|
|
ret += sizeof(cloc_timeW);
|
|
|
|
}else {
|
|
|
|
ret += GetLocaleInfoW(lcid_tmp, time_data[i]|LOCALE_NOUSEROVERRIDE,
|
|
|
|
(wchar_t*)&loc->locinfo->lc_time_curr->data[ret], size-ret)*sizeof(wchar_t);
|
|
|
|
}
|
|
|
|
}
|
2013-04-03 22:46:22 +00:00
|
|
|
loc->locinfo->lc_time_curr->lcid = lcid[MSVCRT_LC_TIME];
|
2012-12-09 03:17:14 +00:00
|
|
|
|
|
|
|
return loc;
|
2007-03-14 20:24:57 +00:00
|
|
|
}
|
2008-05-28 21:08:23 +00:00
|
|
|
|
2008-06-06 17:49:24 +00:00
|
|
|
/*********************************************************************
|
2012-12-09 03:17:14 +00:00
|
|
|
* setlocale (MSVCRT.@)
|
2008-06-06 17:49:24 +00:00
|
|
|
*/
|
2012-12-09 03:17:14 +00:00
|
|
|
char* CDECL setlocale(int category, const char* locale)
|
|
|
|
{
|
|
|
|
MSVCRT__locale_t loc;
|
|
|
|
MSVCRT_pthreadlocinfo locinfo = get_locinfo();
|
|
|
|
|
2013-04-03 22:46:22 +00:00
|
|
|
if(category<MSVCRT_LC_MIN || category>MSVCRT_LC_MAX)
|
2012-12-09 03:17:14 +00:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if(!locale) {
|
2013-04-03 22:46:22 +00:00
|
|
|
if(category == MSVCRT_LC_ALL)
|
2012-12-09 03:17:14 +00:00
|
|
|
return construct_lc_all(locinfo);
|
|
|
|
|
|
|
|
return locinfo->lc_category[category].locale;
|
|
|
|
}
|
2008-06-06 17:49:24 +00:00
|
|
|
|
2012-12-09 03:17:14 +00:00
|
|
|
loc = MSVCRT__create_locale(category, locale);
|
|
|
|
if(!loc) {
|
|
|
|
WARN("%d %s failed\n", category, locale);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
LOCK_LOCALE;
|
|
|
|
|
|
|
|
switch(category) {
|
2013-04-03 22:46:22 +00:00
|
|
|
case MSVCRT_LC_ALL:
|
|
|
|
case MSVCRT_LC_COLLATE:
|
2012-12-09 03:17:14 +00:00
|
|
|
locinfo->lc_collate_cp = loc->locinfo->lc_collate_cp;
|
2013-04-03 22:46:22 +00:00
|
|
|
locinfo->lc_handle[MSVCRT_LC_COLLATE] =
|
|
|
|
loc->locinfo->lc_handle[MSVCRT_LC_COLLATE];
|
|
|
|
swap_pointers((void**)&locinfo->lc_category[MSVCRT_LC_COLLATE].locale,
|
|
|
|
(void**)&loc->locinfo->lc_category[MSVCRT_LC_COLLATE].locale);
|
|
|
|
swap_pointers((void**)&locinfo->lc_category[MSVCRT_LC_COLLATE].refcount,
|
|
|
|
(void**)&loc->locinfo->lc_category[MSVCRT_LC_COLLATE].refcount);
|
|
|
|
|
|
|
|
if(category != MSVCRT_LC_ALL)
|
2012-12-09 03:17:14 +00:00
|
|
|
break;
|
|
|
|
/* fall through */
|
2013-04-03 22:46:22 +00:00
|
|
|
case MSVCRT_LC_CTYPE:
|
|
|
|
locinfo->lc_handle[MSVCRT_LC_CTYPE] =
|
|
|
|
loc->locinfo->lc_handle[MSVCRT_LC_CTYPE];
|
|
|
|
swap_pointers((void**)&locinfo->lc_category[MSVCRT_LC_CTYPE].locale,
|
|
|
|
(void**)&loc->locinfo->lc_category[MSVCRT_LC_CTYPE].locale);
|
|
|
|
swap_pointers((void**)&locinfo->lc_category[MSVCRT_LC_CTYPE].refcount,
|
|
|
|
(void**)&loc->locinfo->lc_category[MSVCRT_LC_CTYPE].refcount);
|
2012-12-09 03:17:14 +00:00
|
|
|
|
|
|
|
locinfo->lc_codepage = loc->locinfo->lc_codepage;
|
|
|
|
locinfo->lc_clike = loc->locinfo->lc_clike;
|
|
|
|
locinfo->mb_cur_max = loc->locinfo->mb_cur_max;
|
|
|
|
|
|
|
|
swap_pointers((void**)&locinfo->ctype1_refcount,
|
|
|
|
(void**)&loc->locinfo->ctype1_refcount);
|
|
|
|
swap_pointers((void**)&locinfo->ctype1, (void**)&loc->locinfo->ctype1);
|
|
|
|
swap_pointers((void**)&locinfo->pctype, (void**)&loc->locinfo->pctype);
|
|
|
|
swap_pointers((void**)&locinfo->pclmap, (void**)&loc->locinfo->pclmap);
|
|
|
|
swap_pointers((void**)&locinfo->pcumap, (void**)&loc->locinfo->pcumap);
|
|
|
|
|
2013-04-03 22:46:22 +00:00
|
|
|
if(category != MSVCRT_LC_ALL)
|
2012-12-09 03:17:14 +00:00
|
|
|
break;
|
|
|
|
/* fall through */
|
2013-04-03 22:46:22 +00:00
|
|
|
case MSVCRT_LC_MONETARY:
|
|
|
|
locinfo->lc_handle[MSVCRT_LC_MONETARY] =
|
|
|
|
loc->locinfo->lc_handle[MSVCRT_LC_MONETARY];
|
|
|
|
swap_pointers((void**)&locinfo->lc_category[MSVCRT_LC_MONETARY].locale,
|
|
|
|
(void**)&loc->locinfo->lc_category[MSVCRT_LC_MONETARY].locale);
|
|
|
|
swap_pointers((void**)&locinfo->lc_category[MSVCRT_LC_MONETARY].refcount,
|
|
|
|
(void**)&loc->locinfo->lc_category[MSVCRT_LC_MONETARY].refcount);
|
2012-12-09 03:17:14 +00:00
|
|
|
|
|
|
|
swap_pointers((void**)&locinfo->lconv->int_curr_symbol,
|
|
|
|
(void**)&loc->locinfo->lconv->int_curr_symbol);
|
|
|
|
swap_pointers((void**)&locinfo->lconv->currency_symbol,
|
|
|
|
(void**)&loc->locinfo->lconv->currency_symbol);
|
|
|
|
swap_pointers((void**)&locinfo->lconv->mon_decimal_point,
|
|
|
|
(void**)&loc->locinfo->lconv->mon_decimal_point);
|
|
|
|
swap_pointers((void**)&locinfo->lconv->mon_thousands_sep,
|
|
|
|
(void**)&loc->locinfo->lconv->mon_thousands_sep);
|
|
|
|
swap_pointers((void**)&locinfo->lconv->mon_grouping,
|
|
|
|
(void**)&loc->locinfo->lconv->mon_grouping);
|
|
|
|
swap_pointers((void**)&locinfo->lconv->positive_sign,
|
|
|
|
(void**)&loc->locinfo->lconv->positive_sign);
|
|
|
|
swap_pointers((void**)&locinfo->lconv->negative_sign,
|
|
|
|
(void**)&loc->locinfo->lconv->negative_sign);
|
|
|
|
locinfo->lconv->int_frac_digits = loc->locinfo->lconv->int_frac_digits;
|
|
|
|
locinfo->lconv->frac_digits = loc->locinfo->lconv->frac_digits;
|
|
|
|
locinfo->lconv->p_cs_precedes = loc->locinfo->lconv->p_cs_precedes;
|
|
|
|
locinfo->lconv->p_sep_by_space = loc->locinfo->lconv->p_sep_by_space;
|
|
|
|
locinfo->lconv->n_cs_precedes = loc->locinfo->lconv->n_cs_precedes;
|
|
|
|
locinfo->lconv->n_sep_by_space = loc->locinfo->lconv->n_sep_by_space;
|
|
|
|
locinfo->lconv->p_sign_posn = loc->locinfo->lconv->p_sign_posn;
|
|
|
|
locinfo->lconv->n_sign_posn = loc->locinfo->lconv->n_sign_posn;
|
|
|
|
|
2013-04-03 22:46:22 +00:00
|
|
|
if(category != MSVCRT_LC_ALL)
|
2012-12-09 03:17:14 +00:00
|
|
|
break;
|
|
|
|
/* fall through */
|
2013-04-03 22:46:22 +00:00
|
|
|
case MSVCRT_LC_NUMERIC:
|
|
|
|
locinfo->lc_handle[MSVCRT_LC_NUMERIC] =
|
|
|
|
loc->locinfo->lc_handle[MSVCRT_LC_NUMERIC];
|
|
|
|
swap_pointers((void**)&locinfo->lc_category[MSVCRT_LC_NUMERIC].locale,
|
|
|
|
(void**)&loc->locinfo->lc_category[MSVCRT_LC_NUMERIC].locale);
|
|
|
|
swap_pointers((void**)&locinfo->lc_category[MSVCRT_LC_NUMERIC].refcount,
|
|
|
|
(void**)&loc->locinfo->lc_category[MSVCRT_LC_NUMERIC].refcount);
|
2012-12-09 03:17:14 +00:00
|
|
|
|
|
|
|
swap_pointers((void**)&locinfo->lconv->decimal_point,
|
|
|
|
(void**)&loc->locinfo->lconv->decimal_point);
|
|
|
|
swap_pointers((void**)&locinfo->lconv->thousands_sep,
|
|
|
|
(void**)&loc->locinfo->lconv->thousands_sep);
|
|
|
|
swap_pointers((void**)&locinfo->lconv->grouping,
|
|
|
|
(void**)&loc->locinfo->lconv->grouping);
|
|
|
|
|
2013-04-03 22:46:22 +00:00
|
|
|
if(category != MSVCRT_LC_ALL)
|
2012-12-09 03:17:14 +00:00
|
|
|
break;
|
|
|
|
/* fall through */
|
2013-04-03 22:46:22 +00:00
|
|
|
case MSVCRT_LC_TIME:
|
|
|
|
locinfo->lc_handle[MSVCRT_LC_TIME] =
|
|
|
|
loc->locinfo->lc_handle[MSVCRT_LC_TIME];
|
|
|
|
swap_pointers((void**)&locinfo->lc_category[MSVCRT_LC_TIME].locale,
|
|
|
|
(void**)&loc->locinfo->lc_category[MSVCRT_LC_TIME].locale);
|
|
|
|
swap_pointers((void**)&locinfo->lc_category[MSVCRT_LC_TIME].refcount,
|
|
|
|
(void**)&loc->locinfo->lc_category[MSVCRT_LC_TIME].refcount);
|
2012-12-09 03:17:14 +00:00
|
|
|
swap_pointers((void**)&locinfo->lc_time_curr,
|
|
|
|
(void**)&loc->locinfo->lc_time_curr);
|
|
|
|
|
2013-04-03 22:46:22 +00:00
|
|
|
if(category != MSVCRT_LC_ALL)
|
2012-12-09 03:17:14 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
MSVCRT__free_locale(loc);
|
|
|
|
UNLOCK_LOCALE;
|
|
|
|
|
|
|
|
if(locinfo == MSVCRT_locale->locinfo) {
|
|
|
|
int i;
|
|
|
|
|
2012-12-13 21:13:06 +00:00
|
|
|
__lc_codepage = locinfo->lc_codepage;
|
2012-12-09 03:17:14 +00:00
|
|
|
MSVCRT___lc_collate_cp = locinfo->lc_collate_cp;
|
|
|
|
__mb_cur_max = locinfo->mb_cur_max;
|
|
|
|
_pctype = locinfo->pctype;
|
|
|
|
for(i=LC_MIN; i<=LC_MAX; i++)
|
|
|
|
MSVCRT___lc_handle[i] = MSVCRT_locale->locinfo->lc_handle[i];
|
|
|
|
}
|
|
|
|
|
2013-04-03 22:46:22 +00:00
|
|
|
if(category == MSVCRT_LC_ALL)
|
2012-12-09 03:17:14 +00:00
|
|
|
return construct_lc_all(locinfo);
|
|
|
|
|
2013-01-28 23:44:29 +00:00
|
|
|
_Analysis_assume_(category <= 5);
|
2012-12-09 03:17:14 +00:00
|
|
|
return locinfo->lc_category[category].locale;
|
2008-06-06 17:49:24 +00:00
|
|
|
}
|
|
|
|
|
2012-12-09 03:17:14 +00:00
|
|
|
/* _configthreadlocale - not exported in native msvcrt */
|
|
|
|
int CDECL _configthreadlocale(int type)
|
2008-05-28 21:08:23 +00:00
|
|
|
{
|
2012-12-09 03:17:14 +00:00
|
|
|
thread_data_t *data = msvcrt_get_thread_data();
|
|
|
|
MSVCRT__locale_t locale;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if(!data)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
ret = (data->have_locale ? _ENABLE_PER_THREAD_LOCALE : _DISABLE_PER_THREAD_LOCALE);
|
|
|
|
|
|
|
|
if(type == _ENABLE_PER_THREAD_LOCALE) {
|
|
|
|
if(!data->have_locale) {
|
|
|
|
/* Copy current global locale */
|
|
|
|
locale = MSVCRT__create_locale(LC_ALL, setlocale(LC_ALL, NULL));
|
|
|
|
if(!locale)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
data->locinfo = locale->locinfo;
|
|
|
|
data->mbcinfo = locale->mbcinfo;
|
|
|
|
data->have_locale = TRUE;
|
2013-04-03 22:46:22 +00:00
|
|
|
MSVCRT_free(locale);
|
2012-12-09 03:17:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(type == _DISABLE_PER_THREAD_LOCALE) {
|
|
|
|
if(data->have_locale) {
|
|
|
|
free_locinfo(data->locinfo);
|
|
|
|
free_mbcinfo(data->mbcinfo);
|
|
|
|
data->locinfo = MSVCRT_locale->locinfo;
|
|
|
|
data->mbcinfo = MSVCRT_locale->mbcinfo;
|
|
|
|
data->have_locale = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!type)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
return -1;
|
2008-05-28 21:08:23 +00:00
|
|
|
}
|
2008-07-26 11:54:54 +00:00
|
|
|
|
|
|
|
/*********************************************************************
|
2012-12-09 03:17:14 +00:00
|
|
|
* _getmbcp (MSVCRT.@)
|
2008-07-26 11:54:54 +00:00
|
|
|
*/
|
2012-12-09 03:17:14 +00:00
|
|
|
int CDECL _getmbcp(void)
|
2008-07-26 11:54:54 +00:00
|
|
|
{
|
2012-12-09 03:17:14 +00:00
|
|
|
return get_mbcinfo()->mbcodepage;
|
2008-07-26 11:54:54 +00:00
|
|
|
}
|
|
|
|
|
2012-12-09 03:17:14 +00:00
|
|
|
extern unsigned int __setlc_active;
|
2008-07-26 11:54:54 +00:00
|
|
|
/*********************************************************************
|
2012-12-09 03:17:14 +00:00
|
|
|
* ___setlc_active_func (MSVCRT.@)
|
2008-07-26 11:54:54 +00:00
|
|
|
*/
|
|
|
|
unsigned int CDECL ___setlc_active_func(void)
|
|
|
|
{
|
|
|
|
return __setlc_active;
|
|
|
|
}
|
2010-07-09 14:33:03 +00:00
|
|
|
|
2012-12-09 03:17:14 +00:00
|
|
|
extern unsigned int __unguarded_readlc_active;
|
2010-07-09 14:33:03 +00:00
|
|
|
/*********************************************************************
|
2012-12-09 03:17:14 +00:00
|
|
|
* ___unguarded_readlc_active_add_func (MSVCRT.@)
|
2010-07-09 14:33:03 +00:00
|
|
|
*/
|
2012-12-09 03:17:14 +00:00
|
|
|
unsigned int * CDECL ___unguarded_readlc_active_add_func(void)
|
2010-07-09 14:33:03 +00:00
|
|
|
{
|
2012-12-09 03:17:14 +00:00
|
|
|
return &__unguarded_readlc_active;
|
|
|
|
}
|
2010-07-09 14:33:03 +00:00
|
|
|
|
2012-12-09 03:17:14 +00:00
|
|
|
MSVCRT__locale_t global_locale = NULL;
|
|
|
|
void __init_global_locale()
|
|
|
|
{
|
|
|
|
unsigned i;
|
2013-01-28 23:44:29 +00:00
|
|
|
|
2012-12-09 03:17:14 +00:00
|
|
|
LOCK_LOCALE;
|
2012-12-13 16:32:17 +00:00
|
|
|
/* Someone created it before us */
|
|
|
|
if(global_locale)
|
|
|
|
return;
|
2012-12-09 03:17:14 +00:00
|
|
|
global_locale = MSVCRT__create_locale(0, "C");
|
2013-01-28 23:44:29 +00:00
|
|
|
|
2012-12-13 21:13:06 +00:00
|
|
|
__lc_codepage = MSVCRT_locale->locinfo->lc_codepage;
|
2012-12-09 03:17:14 +00:00
|
|
|
MSVCRT___lc_collate_cp = MSVCRT_locale->locinfo->lc_collate_cp;
|
|
|
|
__mb_cur_max = MSVCRT_locale->locinfo->mb_cur_max;
|
|
|
|
for(i=LC_MIN; i<=LC_MAX; i++)
|
|
|
|
MSVCRT___lc_handle[i] = MSVCRT_locale->locinfo->lc_handle[i];
|
|
|
|
_setmbcp(_MB_CP_ANSI);
|
|
|
|
UNLOCK_LOCALE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
const unsigned short **__p__pctype(void)
|
|
|
|
{
|
|
|
|
return &get_locinfo()->pctype;
|
|
|
|
}
|
|
|
|
|
|
|
|
const unsigned short* __cdecl __pctype_func(void)
|
|
|
|
{
|
|
|
|
return get_locinfo()->pctype;
|
2010-07-09 14:33:03 +00:00
|
|
|
}
|
2012-12-09 03:17:14 +00:00
|
|
|
|