2001-01-11 00:59:25 +01:00
|
|
|
/*
|
|
|
|
* msvcrt.dll locale functions
|
|
|
|
*
|
|
|
|
* Copyright 2000 Jon Griffiths
|
2002-03-10 00:29:33 +01: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
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2001-01-11 00:59:25 +01:00
|
|
|
*/
|
2002-04-26 21:05:15 +02:00
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include "wine/port.h"
|
|
|
|
|
2009-10-22 22:26:45 +02:00
|
|
|
#include <limits.h>
|
2003-08-07 00:08:04 +02:00
|
|
|
#include <locale.h>
|
2003-09-06 01:08:26 +02:00
|
|
|
#include <stdarg.h>
|
2003-08-07 00:08:04 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
|
2003-09-06 01:08:26 +02:00
|
|
|
#include "windef.h"
|
2001-10-10 04:51:24 +02:00
|
|
|
#include "winbase.h"
|
|
|
|
#include "winuser.h"
|
2006-07-10 11:54:10 +02:00
|
|
|
#include "winnls.h"
|
2001-09-19 22:29:33 +02:00
|
|
|
|
2001-01-11 00:59:25 +01:00
|
|
|
#include "msvcrt.h"
|
2002-02-21 21:22:00 +01:00
|
|
|
#include "mtdll.h"
|
2001-01-11 00:59:25 +01:00
|
|
|
|
2002-01-22 01:57:16 +01:00
|
|
|
#include "wine/debug.h"
|
2015-06-09 01:24:00 +02:00
|
|
|
#include "wine/unicode.h"
|
2002-01-22 01:57:16 +01:00
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(msvcrt);
|
2001-01-11 00:59:25 +01:00
|
|
|
|
|
|
|
#define MAX_ELEM_LEN 64 /* Max length of country/language/CP string */
|
|
|
|
#define MAX_LOCALE_LENGTH 256
|
2010-04-15 14:25:13 +02:00
|
|
|
MSVCRT__locale_t MSVCRT_locale = NULL;
|
2011-10-12 11:56:04 +02:00
|
|
|
unsigned short *MSVCRT__pctype = NULL;
|
2011-12-21 15:59:09 +01:00
|
|
|
unsigned int MSVCRT___lc_codepage = 0;
|
2010-04-16 12:01:35 +02:00
|
|
|
int MSVCRT___lc_collate_cp = 0;
|
2011-05-26 11:40:04 +02:00
|
|
|
LCID MSVCRT___lc_handle[MSVCRT_LC_MAX - MSVCRT_LC_MIN + 1] = { 0 };
|
2011-10-12 11:55:35 +02:00
|
|
|
int MSVCRT___mb_cur_max = 1;
|
2011-05-26 11:40:04 +02:00
|
|
|
static unsigned char charmax = CHAR_MAX;
|
2019-01-23 11:59:05 +01:00
|
|
|
BOOL initial_locale = TRUE;
|
2001-01-11 00:59:25 +01:00
|
|
|
|
|
|
|
#define MSVCRT_LEADBYTE 0x8000
|
2010-04-19 10:58:19 +02:00
|
|
|
#define MSVCRT_C1_DEFINED 0x200
|
2001-01-11 00:59:25 +01:00
|
|
|
|
2019-12-04 16:22:14 +01:00
|
|
|
static const MSVCRT_wchar_t sun[] = {'S','u','n',0};
|
|
|
|
static const MSVCRT_wchar_t mon[] = {'M','o','n',0};
|
|
|
|
static const MSVCRT_wchar_t tue[] = {'T','u','e',0};
|
|
|
|
static const MSVCRT_wchar_t wed[] = {'W','e','d',0};
|
|
|
|
static const MSVCRT_wchar_t thu[] = {'T','h','u',0};
|
|
|
|
static const MSVCRT_wchar_t fri[] = {'F','r','i',0};
|
|
|
|
static const MSVCRT_wchar_t sat[] = {'S','a','t',0};
|
|
|
|
static const MSVCRT_wchar_t sunday[] = {'S','u','n','d','a','y',0};
|
|
|
|
static const MSVCRT_wchar_t monday[] = {'M','o','n','d','a','y',0};
|
|
|
|
static const MSVCRT_wchar_t tuesday[] = {'T','u','e','s','d','a','y',0};
|
|
|
|
static const MSVCRT_wchar_t wednesday[] = {'W','e','d','n','e','s','d','a','y',0};
|
|
|
|
static const MSVCRT_wchar_t thursday[] = {'T','h','u','r','s','d','a','y',0};
|
|
|
|
static const MSVCRT_wchar_t friday[] = {'F','r','i','d','a','y',0};
|
|
|
|
static const MSVCRT_wchar_t saturday[] = {'S','a','t','u','r','d','a','y',0};
|
|
|
|
static const MSVCRT_wchar_t jan[] = {'J','a','n',0};
|
|
|
|
static const MSVCRT_wchar_t feb[] = {'F','e','b',0};
|
|
|
|
static const MSVCRT_wchar_t mar[] = {'M','a','r',0};
|
|
|
|
static const MSVCRT_wchar_t apr[] = {'A','p','r',0};
|
|
|
|
static const MSVCRT_wchar_t may[] = {'M','a','y',0};
|
|
|
|
static const MSVCRT_wchar_t jun[] = {'J','u','n',0};
|
|
|
|
static const MSVCRT_wchar_t jul[] = {'J','u','l',0};
|
|
|
|
static const MSVCRT_wchar_t aug[] = {'A','u','g',0};
|
|
|
|
static const MSVCRT_wchar_t sep[] = {'S','e','p',0};
|
|
|
|
static const MSVCRT_wchar_t oct[] = {'O','c','t',0};
|
|
|
|
static const MSVCRT_wchar_t nov[] = {'N','o','v',0};
|
|
|
|
static const MSVCRT_wchar_t dec[] = {'D','e','c',0};
|
|
|
|
static const MSVCRT_wchar_t january[] = {'J','a','n','u','a','r','y',0};
|
|
|
|
static const MSVCRT_wchar_t february[] = {'F','e','b','r','u','a','r','y',0};
|
|
|
|
static const MSVCRT_wchar_t march[] = {'M','a','r','c','h',0};
|
|
|
|
static const MSVCRT_wchar_t april[] = {'A','p','r','i','l',0};
|
|
|
|
static const MSVCRT_wchar_t june[] = {'J','u','n','e',0};
|
|
|
|
static const MSVCRT_wchar_t july[] = {'J','u','l','y',0};
|
|
|
|
static const MSVCRT_wchar_t august[] = {'A','u','g','u','s','t',0};
|
|
|
|
static const MSVCRT_wchar_t september[] = {'S','e','p','t','e','m','b','e','r',0};
|
|
|
|
static const MSVCRT_wchar_t october[] = {'O','c','t','o','b','e','r',0};
|
|
|
|
static const MSVCRT_wchar_t november[] = {'N','o','v','e','m','b','e','r',0};
|
|
|
|
static const MSVCRT_wchar_t december[] = {'D','e','c','e','m','b','e','r',0};
|
|
|
|
static const MSVCRT_wchar_t am[] = {'A','M',0};
|
|
|
|
static const MSVCRT_wchar_t pm[] = {'P','M',0};
|
|
|
|
static const MSVCRT_wchar_t cloc_short_date[] = {'M','M','/','d','d','/','y','y',0};
|
|
|
|
static const MSVCRT_wchar_t cloc_date[] = {'d','d','d','d',',',' ','M','M','M','M',' ','d','d',',',' ','y','y','y','y',0};
|
|
|
|
static const MSVCRT_wchar_t cloc_time[] = {'H','H',':','m','m',':','s','s',0};
|
|
|
|
|
|
|
|
#if _MSVCR_VER >= 110
|
|
|
|
static const MSVCRT_wchar_t en_us[] = {'e','n','-','U','S',0};
|
|
|
|
#endif
|
|
|
|
|
|
|
|
MSVCRT___lc_time_data cloc_time_data =
|
|
|
|
{
|
|
|
|
{{"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat",
|
|
|
|
"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday",
|
|
|
|
"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec",
|
|
|
|
"January", "February", "March", "April", "May", "June", "July",
|
|
|
|
"August", "September", "October", "November", "December",
|
|
|
|
"AM", "PM", "MM/dd/yy", "dddd, MMMM dd, yyyy", "HH:mm:ss"}},
|
|
|
|
#if _MSVCR_VER < 110
|
|
|
|
MAKELCID(LANG_ENGLISH, SORT_DEFAULT),
|
|
|
|
#endif
|
|
|
|
{1, 0},
|
|
|
|
{{sun, mon, tue, wed, thu, fri, sat,
|
|
|
|
sunday, monday, tuesday, wednesday, thursday, friday, saturday,
|
|
|
|
jan, feb, mar, apr, may, jun, jul, aug, sep, oct, nov, dec,
|
|
|
|
january, february, march, april, may, june, july,
|
|
|
|
august, september, october, november, december,
|
|
|
|
am, pm, cloc_short_date, cloc_date, cloc_time}},
|
|
|
|
#if _MSVCR_VER >= 110
|
|
|
|
en_us,
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
2010-05-09 23:39:17 +02:00
|
|
|
/* Friendly country strings & language names abbreviations. */
|
2006-12-14 15:47:24 +01:00
|
|
|
static const char * const _country_synonyms[] =
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
2010-05-09 23:39:17 +02: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",
|
2012-06-13 19:47:54 +02:00
|
|
|
"portuguese", "ptb",
|
2010-05-09 23:39:17 +02:00
|
|
|
"portuguese-brazil", "ptb",
|
|
|
|
"spanish-mexican", "esm",
|
|
|
|
"norwegian-bokmal", "nor",
|
|
|
|
"norwegian-nynorsk", "non",
|
|
|
|
"spanish-modern", "esn"
|
2001-01-11 00:59:25 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/* INTERNAL: Map a synonym to an ISO code */
|
|
|
|
static void remap_synonym(char *name)
|
|
|
|
{
|
2009-05-27 11:39:05 +02:00
|
|
|
unsigned int i;
|
2018-07-26 00:05:52 +02:00
|
|
|
for (i = 0; i < ARRAY_SIZE(_country_synonyms); i += 2)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
2019-03-26 11:31:09 +01:00
|
|
|
if (!MSVCRT__stricmp(_country_synonyms[i],name))
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
|
|
|
TRACE(":Mapping synonym %s to %s\n",name,_country_synonyms[i+1]);
|
2011-10-17 00:42:28 +02:00
|
|
|
strcpy(name, _country_synonyms[i+1]);
|
2001-01-11 00:59:25 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Note: Flags are weighted in order of matching importance */
|
2018-05-09 17:36:17 +02:00
|
|
|
#define FOUND_SNAME 0x8
|
2001-01-11 00:59:25 +01:00
|
|
|
#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];
|
2020-01-24 18:28:53 +01:00
|
|
|
DWORD found_codepage;
|
2001-01-11 00:59:25 +01:00
|
|
|
unsigned int match_flags;
|
|
|
|
LANGID found_lang_id;
|
|
|
|
} locale_search_t;
|
|
|
|
|
|
|
|
#define CONTINUE_LOOKING TRUE
|
|
|
|
#define STOP_LOOKING FALSE
|
|
|
|
|
|
|
|
/* INTERNAL: Get and compare locale info with a given string */
|
2010-05-09 23:39:17 +02:00
|
|
|
static int compare_info(LCID lcid, DWORD flags, char* buff, const char* cmp, BOOL exact)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
2010-05-09 23:39:17 +02:00
|
|
|
int len;
|
|
|
|
|
2012-12-18 11:39:00 +01:00
|
|
|
if(!cmp[0])
|
|
|
|
return 0;
|
|
|
|
|
2001-01-11 00:59:25 +01:00
|
|
|
buff[0] = 0;
|
2010-05-09 23:39:17 +02:00
|
|
|
GetLocaleInfoA(lcid, flags|LOCALE_NOUSEROVERRIDE, buff, MAX_ELEM_LEN);
|
2012-12-18 11:39:00 +01:00
|
|
|
if (!buff[0])
|
2001-01-11 00:59:25 +01:00
|
|
|
return 0;
|
2010-05-09 23:39:17 +02:00
|
|
|
|
|
|
|
/* Partial matches are only allowed on language/country names */
|
|
|
|
len = strlen(cmp);
|
|
|
|
if(exact || len<=3)
|
2019-03-26 11:31:09 +01:00
|
|
|
return !MSVCRT__stricmp(cmp, buff);
|
2010-05-09 23:39:17 +02:00
|
|
|
else
|
2019-03-26 11:31:13 +01:00
|
|
|
return !MSVCRT__strnicmp(cmp, buff, len);
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL CALLBACK
|
2005-09-12 17:14:06 +02:00
|
|
|
find_best_locale_proc(HMODULE hModule, LPCSTR type, LPCSTR name, WORD LangID, LONG_PTR lParam)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
|
2018-05-09 17:36:17 +02:00
|
|
|
#if _MSVCR_VER >= 110
|
|
|
|
if (!res->search_country[0] && !res->search_codepage[0] &&
|
|
|
|
compare_info(lcid,LOCALE_SNAME,buff,res->search_language, TRUE))
|
|
|
|
{
|
|
|
|
TRACE(":Found locale: %s->%s\n", res->search_language, buff);
|
|
|
|
res->match_flags = FOUND_SNAME;
|
|
|
|
res->found_lang_id = LangID;
|
|
|
|
return STOP_LOOKING;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2001-01-11 00:59:25 +01:00
|
|
|
/* Check Language */
|
2010-05-09 23:39:17 +02: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))
|
2001-01-11 00:59:25 +01: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 */
|
2010-05-09 23:39:17 +02: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))
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
|
|
|
TRACE("Found country:%s->%s\n", res->search_country, buff);
|
|
|
|
flags |= FOUND_COUNTRY;
|
|
|
|
}
|
2012-12-18 11:39:00 +01:00
|
|
|
else if (!flags && (res->match_flags & FOUND_COUNTRY))
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
|
|
|
return CONTINUE_LOOKING;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check codepage */
|
2010-05-09 23:39:17 +02:00
|
|
|
if (compare_info(lcid,LOCALE_IDEFAULTCODEPAGE,buff,res->search_codepage, TRUE) ||
|
|
|
|
(compare_info(lcid,LOCALE_IDEFAULTANSICODEPAGE,buff,res->search_codepage, TRUE)))
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
|
|
|
TRACE("Found codepage:%s->%s\n", res->search_codepage, buff);
|
|
|
|
flags |= FOUND_CODEPAGE;
|
2020-01-24 18:28:53 +01:00
|
|
|
res->found_codepage = atoi(res->search_codepage);
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
2012-12-18 11:39:00 +01:00
|
|
|
else if (!flags && (res->match_flags & FOUND_CODEPAGE))
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
|
|
|
return CONTINUE_LOOKING;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (flags > res->match_flags)
|
|
|
|
{
|
|
|
|
/* Found a better match than previously */
|
|
|
|
res->match_flags = flags;
|
|
|
|
res->found_lang_id = LangID;
|
|
|
|
}
|
2008-09-23 14:31:47 +02:00
|
|
|
if ((flags & (FOUND_LANGUAGE | FOUND_COUNTRY | FOUND_CODEPAGE)) ==
|
|
|
|
(FOUND_LANGUAGE | FOUND_COUNTRY | FOUND_CODEPAGE))
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
|
|
|
TRACE(":found exact locale match\n");
|
|
|
|
return STOP_LOOKING;
|
|
|
|
}
|
|
|
|
return CONTINUE_LOOKING;
|
|
|
|
}
|
|
|
|
|
|
|
|
extern int atoi(const char *);
|
|
|
|
|
|
|
|
/* Internal: Find the LCID for a locale specification */
|
2018-05-09 17:36:17 +02:00
|
|
|
LCID MSVCRT_locale_to_LCID(const char *locale, unsigned short *codepage, BOOL *sname)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
2015-06-24 15:13:07 +02:00
|
|
|
thread_data_t *data = msvcrt_get_thread_data();
|
2010-04-15 14:26:01 +02:00
|
|
|
LCID lcid;
|
|
|
|
locale_search_t search;
|
2011-08-22 21:31:47 +02:00
|
|
|
const char *cp, *region;
|
2010-04-15 14:26:01 +02:00
|
|
|
|
2015-06-24 15:13:07 +02:00
|
|
|
if (!strcmp(locale, data->cached_locale)) {
|
|
|
|
if (codepage)
|
|
|
|
*codepage = data->cached_cp;
|
2018-05-09 17:36:17 +02:00
|
|
|
if (sname)
|
|
|
|
*sname = data->cached_sname;
|
2015-06-24 15:13:07 +02:00
|
|
|
return data->cached_lcid;
|
|
|
|
}
|
|
|
|
|
2010-04-15 14:26:01 +02:00
|
|
|
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);
|
2011-10-13 23:29:27 +02:00
|
|
|
if(region && cp-region-1<MAX_ELEM_LEN)
|
2010-04-19 10:58:10 +02:00
|
|
|
search.search_country[cp-region-1] = '\0';
|
2010-04-15 14:26:01 +02:00
|
|
|
if(cp-locale < MAX_ELEM_LEN)
|
|
|
|
search.search_language[cp-locale] = '\0';
|
|
|
|
} else
|
|
|
|
search.search_codepage[0] = '\0';
|
|
|
|
|
2010-05-09 23:39:17 +02:00
|
|
|
if(!search.search_country[0] && !search.search_codepage[0])
|
|
|
|
remap_synonym(search.search_language);
|
2010-04-15 14:26:01 +02:00
|
|
|
|
2019-03-26 11:31:09 +01:00
|
|
|
if(!MSVCRT__stricmp(search.search_country, "China"))
|
2018-04-05 23:13:51 +02:00
|
|
|
strcpy(search.search_country, "People's Republic of China");
|
|
|
|
|
2010-04-15 14:26:01 +02:00
|
|
|
EnumResourceLanguagesA(GetModuleHandleA("KERNEL32"), (LPSTR)RT_STRING,
|
|
|
|
(LPCSTR)LOCALE_ILANGUAGE,find_best_locale_proc,
|
|
|
|
(LONG_PTR)&search);
|
|
|
|
|
|
|
|
if (!search.match_flags)
|
2010-04-19 10:58:10 +02:00
|
|
|
return -1;
|
2010-04-15 14:26:01 +02:00
|
|
|
|
|
|
|
/* If we were given something that didn't match, fail */
|
2018-05-09 17:36:17 +02:00
|
|
|
if (search.search_language[0] && !(search.match_flags & (FOUND_SNAME | FOUND_LANGUAGE)))
|
|
|
|
return -1;
|
2010-04-15 14:26:01 +02:00
|
|
|
if (search.search_country[0] && !(search.match_flags & FOUND_COUNTRY))
|
2010-04-19 10:58:10 +02:00
|
|
|
return -1;
|
2010-04-15 14:26:01 +02:00
|
|
|
|
|
|
|
lcid = MAKELCID(search.found_lang_id, SORT_DEFAULT);
|
|
|
|
|
|
|
|
/* Populate partial locale, translating LCID to locale string elements */
|
2012-12-18 11:38:33 +01:00
|
|
|
if (!(search.match_flags & FOUND_CODEPAGE)) {
|
2010-04-15 14:26:01 +02:00
|
|
|
/* Even if a codepage is not enumerated for a locale
|
|
|
|
* it can be set if valid */
|
|
|
|
if (search.search_codepage[0]) {
|
2020-01-24 18:28:53 +01:00
|
|
|
search.found_codepage = atoi(search.search_codepage);
|
|
|
|
if (!IsValidCodePage(atoi(search.search_codepage)))
|
|
|
|
{
|
2010-04-15 14:26:01 +02:00
|
|
|
/* Special codepage values: OEM & ANSI */
|
2019-03-26 11:31:09 +01:00
|
|
|
if (!MSVCRT__stricmp(search.search_codepage,"OCP")) {
|
2020-01-24 18:28:53 +01:00
|
|
|
GetLocaleInfoW(lcid, LOCALE_IDEFAULTCODEPAGE | LOCALE_RETURN_NUMBER,
|
|
|
|
(WCHAR *)&search.found_codepage, sizeof(DWORD)/sizeof(WCHAR));
|
2019-03-26 11:31:09 +01:00
|
|
|
} else if (!MSVCRT__stricmp(search.search_codepage,"ACP")) {
|
2020-01-24 18:28:53 +01:00
|
|
|
GetLocaleInfoW(lcid, LOCALE_IDEFAULTANSICODEPAGE | LOCALE_RETURN_NUMBER,
|
|
|
|
(WCHAR *)&search.found_codepage, sizeof(DWORD)/sizeof(WCHAR));
|
2010-04-15 14:26:01 +02:00
|
|
|
} else
|
2010-04-19 10:58:10 +02:00
|
|
|
return -1;
|
2020-01-24 18:28:53 +01:00
|
|
|
if (!search.found_codepage)
|
2010-04-19 10:58:10 +02:00
|
|
|
return -1;
|
2010-04-15 14:26:01 +02:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* Prefer ANSI codepages if present */
|
2020-01-24 18:28:53 +01:00
|
|
|
GetLocaleInfoW(lcid, LOCALE_IDEFAULTANSICODEPAGE | LOCALE_RETURN_NUMBER,
|
|
|
|
(WCHAR *)&search.found_codepage, sizeof(DWORD)/sizeof(WCHAR));
|
|
|
|
if (!search.found_codepage)
|
|
|
|
GetLocaleInfoW(lcid, LOCALE_IDEFAULTCODEPAGE | LOCALE_RETURN_NUMBER,
|
|
|
|
(WCHAR *)&search.found_codepage, sizeof(DWORD)/sizeof(WCHAR));
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
|
|
|
}
|
2012-12-18 11:38:33 +01:00
|
|
|
if (codepage)
|
2020-01-24 18:28:53 +01:00
|
|
|
*codepage = search.found_codepage;
|
2018-05-09 17:36:17 +02:00
|
|
|
if (sname)
|
|
|
|
*sname = (search.match_flags & FOUND_SNAME) != 0;
|
2010-04-15 14:26:01 +02:00
|
|
|
|
2015-06-24 15:13:07 +02:00
|
|
|
if (strlen(locale) < sizeof(data->cached_locale)) {
|
|
|
|
strcpy(data->cached_locale, locale);
|
|
|
|
data->cached_lcid = lcid;
|
2020-01-24 18:28:53 +01:00
|
|
|
data->cached_cp = codepage ? *codepage : search.found_codepage;
|
2018-05-09 17:36:17 +02:00
|
|
|
data->cached_sname = (search.match_flags & FOUND_SNAME) != 0;
|
2015-06-24 15:13:07 +02:00
|
|
|
}
|
|
|
|
|
2010-04-15 14:26:01 +02:00
|
|
|
return lcid;
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
|
|
|
|
2018-05-09 17:36:17 +02:00
|
|
|
static BOOL init_category_name(const char *name, int len,
|
|
|
|
MSVCRT_pthreadlocinfo locinfo, int category)
|
|
|
|
{
|
|
|
|
locinfo->lc_category[category].locale = MSVCRT_malloc(len+1);
|
|
|
|
locinfo->lc_category[category].refcount = MSVCRT_malloc(sizeof(int));
|
|
|
|
if(!locinfo->lc_category[category].locale
|
|
|
|
|| !locinfo->lc_category[category].refcount) {
|
|
|
|
MSVCRT_free(locinfo->lc_category[category].locale);
|
|
|
|
MSVCRT_free(locinfo->lc_category[category].refcount);
|
|
|
|
locinfo->lc_category[category].locale = NULL;
|
|
|
|
locinfo->lc_category[category].refcount = NULL;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(locinfo->lc_category[category].locale, name, len);
|
|
|
|
locinfo->lc_category[category].locale[len] = 0;
|
|
|
|
*locinfo->lc_category[category].refcount = 1;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2010-04-08 10:24:25 +02:00
|
|
|
/* INTERNAL: Set lc_handle, lc_id and lc_category in threadlocinfo struct */
|
2012-12-18 11:38:33 +01:00
|
|
|
static BOOL update_threadlocinfo_category(LCID lcid, unsigned short cp,
|
2015-09-24 16:15:40 +02:00
|
|
|
MSVCRT_pthreadlocinfo locinfo, int category)
|
2010-04-08 10:24:25 +02:00
|
|
|
{
|
|
|
|
char buf[256], *p;
|
|
|
|
|
2010-05-09 23:38:11 +02:00
|
|
|
if(GetLocaleInfoA(lcid, LOCALE_ILANGUAGE|LOCALE_NOUSEROVERRIDE, buf, 256)) {
|
2010-04-08 10:24:25 +02:00
|
|
|
p = buf;
|
|
|
|
|
2015-09-24 16:15:40 +02:00
|
|
|
locinfo->lc_id[category].wLanguage = 0;
|
2010-04-08 10:24:25 +02:00
|
|
|
while(*p) {
|
2015-09-24 16:15:40 +02:00
|
|
|
locinfo->lc_id[category].wLanguage *= 16;
|
2010-04-08 10:24:25 +02:00
|
|
|
|
|
|
|
if(*p <= '9')
|
2015-09-24 16:15:40 +02:00
|
|
|
locinfo->lc_id[category].wLanguage += *p-'0';
|
2010-04-08 10:24:25 +02:00
|
|
|
else
|
2015-09-24 16:15:40 +02:00
|
|
|
locinfo->lc_id[category].wLanguage += *p-'a'+10;
|
2010-04-08 10:24:25 +02:00
|
|
|
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
|
2015-09-24 16:15:40 +02:00
|
|
|
locinfo->lc_id[category].wCountry =
|
|
|
|
locinfo->lc_id[category].wLanguage;
|
2010-04-08 10:24:25 +02:00
|
|
|
}
|
|
|
|
|
2015-09-24 16:15:40 +02:00
|
|
|
locinfo->lc_id[category].wCodePage = cp;
|
2010-04-08 10:24:25 +02:00
|
|
|
|
2015-09-24 16:15:40 +02:00
|
|
|
locinfo->lc_handle[category] = lcid;
|
2010-04-08 10:24:25 +02:00
|
|
|
|
2018-05-09 17:36:17 +02:00
|
|
|
if(!locinfo->lc_category[category].locale) {
|
|
|
|
int 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] = '.';
|
|
|
|
sprintf(buf+len, "%d", cp);
|
|
|
|
len += strlen(buf+len);
|
|
|
|
|
|
|
|
return init_category_name(buf, len, locinfo, category);
|
2010-04-08 10:24:25 +02:00
|
|
|
}
|
|
|
|
|
2018-05-09 17:36:17 +02:00
|
|
|
return TRUE;
|
2010-04-08 10:24:25 +02:00
|
|
|
}
|
|
|
|
|
2010-04-15 14:25:13 +02:00
|
|
|
/* INTERNAL: swap pointers values */
|
|
|
|
static inline void swap_pointers(void **p1, void **p2) {
|
|
|
|
void *hlp;
|
2001-01-11 00:59:25 +01:00
|
|
|
|
2010-04-15 14:25:13 +02:00
|
|
|
hlp = *p1;
|
|
|
|
*p1 = *p2;
|
|
|
|
*p2 = hlp;
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
|
|
|
|
2011-05-24 17:22:42 +02:00
|
|
|
/* INTERNAL: returns pthreadlocinfo struct */
|
|
|
|
MSVCRT_pthreadlocinfo get_locinfo(void) {
|
2010-04-15 14:25:34 +02:00
|
|
|
thread_data_t *data = msvcrt_get_thread_data();
|
|
|
|
|
2011-05-24 17:22:42 +02:00
|
|
|
if(!data || !data->have_locale)
|
|
|
|
return MSVCRT_locale->locinfo;
|
2010-04-15 14:25:34 +02:00
|
|
|
|
2011-05-24 17:22:42 +02:00
|
|
|
return data->locinfo;
|
2010-04-15 14:25:34 +02:00
|
|
|
}
|
|
|
|
|
2011-05-24 17:22:32 +02:00
|
|
|
/* INTERNAL: returns pthreadlocinfo struct */
|
2011-10-12 11:54:53 +02:00
|
|
|
MSVCRT_pthreadmbcinfo get_mbcinfo(void) {
|
2011-05-24 17:22:32 +02:00
|
|
|
thread_data_t *data = msvcrt_get_thread_data();
|
|
|
|
|
2011-05-24 17:22:42 +02:00
|
|
|
if(!data || !data->have_locale)
|
|
|
|
return MSVCRT_locale->mbcinfo;
|
2011-05-24 17:22:32 +02:00
|
|
|
|
2011-05-24 17:22:42 +02:00
|
|
|
return data->mbcinfo;
|
2011-05-24 17:22:32 +02:00
|
|
|
}
|
|
|
|
|
2010-04-19 10:58:51 +02:00
|
|
|
/* INTERNAL: constructs string returned by setlocale */
|
2011-05-24 17:22:42 +02:00
|
|
|
static inline char* construct_lc_all(MSVCRT_pthreadlocinfo locinfo) {
|
2010-04-19 10:58:51 +02:00
|
|
|
static char current_lc_all[MAX_LOCALE_LENGTH];
|
|
|
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for(i=MSVCRT_LC_MIN+1; i<MSVCRT_LC_MAX; i++) {
|
2011-05-24 17:22:42 +02:00
|
|
|
if(strcmp(locinfo->lc_category[i].locale,
|
|
|
|
locinfo->lc_category[i+1].locale))
|
2010-04-19 10:58:51 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(i==MSVCRT_LC_MAX)
|
2011-05-24 17:22:42 +02:00
|
|
|
return locinfo->lc_category[MSVCRT_LC_COLLATE].locale;
|
2010-04-19 10:58:51 +02:00
|
|
|
|
|
|
|
sprintf(current_lc_all,
|
|
|
|
"LC_COLLATE=%s;LC_CTYPE=%s;LC_MONETARY=%s;LC_NUMERIC=%s;LC_TIME=%s",
|
2011-05-24 17:22:42 +02: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);
|
2010-04-19 10:58:51 +02:00
|
|
|
|
|
|
|
return current_lc_all;
|
|
|
|
}
|
|
|
|
|
2010-04-15 14:25:13 +02:00
|
|
|
|
2001-01-11 00:59:25 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _Getdays (MSVCRT.@)
|
|
|
|
*/
|
2011-12-07 13:49:09 +01:00
|
|
|
char* CDECL _Getdays(void)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
2011-12-07 13:49:09 +01:00
|
|
|
MSVCRT___lc_time_data *cur = get_locinfo()->lc_time_curr;
|
2019-12-04 15:29:59 +01:00
|
|
|
int i, len, size = 0;
|
2011-12-07 13:49:09 +01:00
|
|
|
char *out;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
2019-12-04 15:29:59 +01:00
|
|
|
for(i=0; i<7; i++) {
|
|
|
|
size += strlen(cur->str.names.short_wday[i]) + 1;
|
|
|
|
size += strlen(cur->str.names.wday[i]) + 1;
|
|
|
|
}
|
2011-12-07 13:49:09 +01:00
|
|
|
out = MSVCRT_malloc(size+1);
|
|
|
|
if(!out)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
size = 0;
|
|
|
|
for(i=0; i<7; i++) {
|
|
|
|
out[size++] = ':';
|
2012-04-11 15:22:12 +02:00
|
|
|
len = strlen(cur->str.names.short_wday[i]);
|
|
|
|
memcpy(&out[size], cur->str.names.short_wday[i], len);
|
2011-12-07 13:49:09 +01:00
|
|
|
size += len;
|
|
|
|
|
|
|
|
out[size++] = ':';
|
2012-04-11 15:22:12 +02:00
|
|
|
len = strlen(cur->str.names.wday[i]);
|
|
|
|
memcpy(&out[size], cur->str.names.wday[i], len);
|
2011-12-07 13:49:09 +01:00
|
|
|
size += len;
|
|
|
|
}
|
2011-12-28 16:29:07 +01:00
|
|
|
out[size] = '\0';
|
2011-12-07 13:49:09 +01:00
|
|
|
|
|
|
|
return out;
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
|
|
|
|
2018-01-04 05:33:01 +01:00
|
|
|
#if _MSVCR_VER >= 110
|
2015-06-09 01:24:00 +02:00
|
|
|
/*********************************************************************
|
2018-01-10 07:21:46 +01:00
|
|
|
* _W_Getdays (MSVCR110.@)
|
2015-06-09 01:24:00 +02:00
|
|
|
*/
|
|
|
|
MSVCRT_wchar_t* CDECL _W_Getdays(void)
|
|
|
|
{
|
|
|
|
MSVCRT___lc_time_data *cur = get_locinfo()->lc_time_curr;
|
|
|
|
MSVCRT_wchar_t *out;
|
2019-12-04 15:30:03 +01:00
|
|
|
int i, len, size = 0;
|
2015-06-09 01:24:00 +02:00
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
2019-12-04 15:30:03 +01:00
|
|
|
for(i=0; i<7; i++) {
|
|
|
|
size += strlenW(cur->wstr.names.short_wday[i]) + 1;
|
|
|
|
size += strlenW(cur->wstr.names.wday[i]) + 1;
|
|
|
|
}
|
2015-06-09 01:24:00 +02:00
|
|
|
out = MSVCRT_malloc((size+1)*sizeof(*out));
|
|
|
|
if(!out)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
size = 0;
|
|
|
|
for(i=0; i<7; i++) {
|
|
|
|
out[size++] = ':';
|
|
|
|
len = strlenW(cur->wstr.names.short_wday[i]);
|
|
|
|
memcpy(&out[size], cur->wstr.names.short_wday[i], len*sizeof(*out));
|
|
|
|
size += len;
|
|
|
|
|
|
|
|
out[size++] = ':';
|
|
|
|
len = strlenW(cur->wstr.names.wday[i]);
|
|
|
|
memcpy(&out[size], cur->wstr.names.wday[i], len*sizeof(*out));
|
|
|
|
size += len;
|
|
|
|
}
|
|
|
|
out[size] = '\0';
|
|
|
|
|
|
|
|
return out;
|
|
|
|
}
|
2018-01-04 05:33:01 +01:00
|
|
|
#endif
|
2015-06-09 01:24:00 +02:00
|
|
|
|
2001-01-11 00:59:25 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _Getmonths (MSVCRT.@)
|
|
|
|
*/
|
2011-12-07 13:49:47 +01:00
|
|
|
char* CDECL _Getmonths(void)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
2011-12-07 13:49:47 +01:00
|
|
|
MSVCRT___lc_time_data *cur = get_locinfo()->lc_time_curr;
|
2019-12-04 15:30:08 +01:00
|
|
|
int i, len, size = 0;
|
2011-12-07 13:49:47 +01:00
|
|
|
char *out;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
2019-12-04 15:30:08 +01:00
|
|
|
for(i=0; i<12; i++) {
|
|
|
|
size += strlen(cur->str.names.short_mon[i]) + 1;
|
|
|
|
size += strlen(cur->str.names.mon[i]) + 1;
|
|
|
|
}
|
2011-12-07 13:49:47 +01:00
|
|
|
out = MSVCRT_malloc(size+1);
|
|
|
|
if(!out)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
size = 0;
|
|
|
|
for(i=0; i<12; i++) {
|
|
|
|
out[size++] = ':';
|
2012-04-11 15:22:12 +02:00
|
|
|
len = strlen(cur->str.names.short_mon[i]);
|
|
|
|
memcpy(&out[size], cur->str.names.short_mon[i], len);
|
2011-12-07 13:49:47 +01:00
|
|
|
size += len;
|
|
|
|
|
|
|
|
out[size++] = ':';
|
2012-04-11 15:22:12 +02:00
|
|
|
len = strlen(cur->str.names.mon[i]);
|
|
|
|
memcpy(&out[size], cur->str.names.mon[i], len);
|
2011-12-07 13:49:47 +01:00
|
|
|
size += len;
|
|
|
|
}
|
2011-12-28 16:29:07 +01:00
|
|
|
out[size] = '\0';
|
2011-12-07 13:49:47 +01:00
|
|
|
|
|
|
|
return out;
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
|
|
|
|
2018-01-04 05:33:01 +01:00
|
|
|
#if _MSVCR_VER >= 110
|
2015-06-09 02:10:01 +02:00
|
|
|
/*********************************************************************
|
2018-01-10 07:21:46 +01:00
|
|
|
* _W_Getmonths (MSVCR110.@)
|
2015-06-09 02:10:01 +02:00
|
|
|
*/
|
|
|
|
MSVCRT_wchar_t* CDECL _W_Getmonths(void)
|
|
|
|
{
|
|
|
|
MSVCRT___lc_time_data *cur = get_locinfo()->lc_time_curr;
|
|
|
|
MSVCRT_wchar_t *out;
|
2019-12-04 15:30:13 +01:00
|
|
|
int i, len, size = 0;
|
2015-06-09 02:10:01 +02:00
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
2019-12-04 15:30:13 +01:00
|
|
|
for(i=0; i<12; i++) {
|
|
|
|
size += strlenW(cur->wstr.names.short_mon[i]) + 1;
|
|
|
|
size += strlenW(cur->wstr.names.mon[i]) + 1;
|
|
|
|
}
|
2015-06-09 02:10:01 +02:00
|
|
|
out = MSVCRT_malloc((size+1)*sizeof(*out));
|
|
|
|
if(!out)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
size = 0;
|
|
|
|
for(i=0; i<12; i++) {
|
|
|
|
out[size++] = ':';
|
|
|
|
len = strlenW(cur->wstr.names.short_mon[i]);
|
|
|
|
memcpy(&out[size], cur->wstr.names.short_mon[i], len*sizeof(*out));
|
|
|
|
size += len;
|
|
|
|
|
|
|
|
out[size++] = ':';
|
|
|
|
len = strlenW(cur->wstr.names.mon[i]);
|
|
|
|
memcpy(&out[size], cur->wstr.names.mon[i], len*sizeof(*out));
|
|
|
|
size += len;
|
|
|
|
}
|
|
|
|
out[size] = '\0';
|
|
|
|
|
|
|
|
return out;
|
|
|
|
}
|
2018-01-04 05:33:01 +01:00
|
|
|
#endif
|
2015-06-09 02:10:01 +02:00
|
|
|
|
2001-01-11 00:59:25 +01:00
|
|
|
/*********************************************************************
|
2005-06-22 20:07:31 +02:00
|
|
|
* _Gettnames (MSVCRT.@)
|
2001-01-11 00:59:25 +01:00
|
|
|
*/
|
2011-12-07 13:48:36 +01:00
|
|
|
void* CDECL _Gettnames(void)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
2011-12-07 13:48:36 +01:00
|
|
|
MSVCRT___lc_time_data *ret, *cur = get_locinfo()->lc_time_curr;
|
2019-12-04 15:30:38 +01:00
|
|
|
unsigned int i, len, size = sizeof(MSVCRT___lc_time_data);
|
2011-12-07 13:48:36 +01:00
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
2018-07-26 00:05:52 +02:00
|
|
|
for(i=0; i<ARRAY_SIZE(cur->str.str); i++)
|
2012-04-11 15:22:12 +02:00
|
|
|
size += strlen(cur->str.str[i])+1;
|
2011-12-07 13:48:36 +01:00
|
|
|
|
|
|
|
ret = MSVCRT_malloc(size);
|
|
|
|
if(!ret)
|
|
|
|
return NULL;
|
2019-12-04 15:30:38 +01:00
|
|
|
memcpy(ret, cur, sizeof(*ret));
|
2011-12-07 13:48:36 +01:00
|
|
|
|
|
|
|
size = 0;
|
2018-07-26 00:05:52 +02:00
|
|
|
for(i=0; i<ARRAY_SIZE(cur->str.str); i++) {
|
2019-12-04 15:30:38 +01:00
|
|
|
len = strlen(cur->str.str[i])+1;
|
|
|
|
memcpy(&ret->data[size], cur->str.str[i], len);
|
2012-04-11 15:22:12 +02:00
|
|
|
ret->str.str[i] = &ret->data[size];
|
2019-12-04 15:30:38 +01:00
|
|
|
size += len;
|
2011-12-07 13:48:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
|
|
|
|
2018-01-04 05:33:01 +01:00
|
|
|
#if _MSVCR_VER >= 110
|
2016-01-20 11:42:14 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _W_Gettnames (MSVCR110.@)
|
|
|
|
*/
|
|
|
|
void* CDECL _W_Gettnames(void)
|
|
|
|
{
|
|
|
|
return _Gettnames();
|
|
|
|
}
|
2018-01-04 05:33:01 +01:00
|
|
|
#endif
|
2016-01-20 11:42:14 +01:00
|
|
|
|
2003-02-11 23:11:17 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* __crtLCMapStringA (MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
int CDECL __crtLCMapStringA(
|
2003-02-11 23:11:17 +01:00
|
|
|
LCID lcid, DWORD mapflags, const char* src, int srclen, char* dst,
|
|
|
|
int dstlen, unsigned int codepage, int xflag
|
|
|
|
) {
|
2006-10-03 20:39:05 +02:00
|
|
|
FIXME("(lcid %x, flags %x, %s(%d), %p(%d), %x, %d), partial stub!\n",
|
2003-02-11 23:11:17 +01:00
|
|
|
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);
|
|
|
|
}
|
2003-06-04 22:24:56 +02:00
|
|
|
|
2010-06-22 12:26:23 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* __crtLCMapStringW (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int CDECL __crtLCMapStringW(LCID lcid, DWORD mapflags, const MSVCRT_wchar_t *src,
|
|
|
|
int srclen, MSVCRT_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);
|
|
|
|
|
|
|
|
return LCMapStringW(lcid, mapflags, src, srclen, dst, dstlen);
|
|
|
|
}
|
|
|
|
|
2007-09-19 17:53:06 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* __crtCompareStringA (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int CDECL __crtCompareStringA( LCID lcid, DWORD flags, const char *src1, int len1,
|
|
|
|
const char *src2, int len2 )
|
|
|
|
{
|
|
|
|
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 );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* __crtCompareStringW (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int CDECL __crtCompareStringW( LCID lcid, DWORD flags, const MSVCRT_wchar_t *src1, int len1,
|
|
|
|
const MSVCRT_wchar_t *src2, int len2 )
|
|
|
|
{
|
|
|
|
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 );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* __crtGetLocaleInfoW (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int CDECL __crtGetLocaleInfoW( LCID lcid, LCTYPE type, MSVCRT_wchar_t *buffer, int len )
|
|
|
|
{
|
|
|
|
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 );
|
|
|
|
}
|
|
|
|
|
2018-01-04 05:33:01 +01:00
|
|
|
#if _MSVCR_VER >= 110
|
2015-06-22 12:52:30 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* __crtGetLocaleInfoEx (MSVC110.@)
|
|
|
|
*/
|
|
|
|
int CDECL __crtGetLocaleInfoEx( const WCHAR *locale, LCTYPE type, MSVCRT_wchar_t *buffer, int len )
|
|
|
|
{
|
|
|
|
TRACE("(%s, %x, %p, %d)\n", debugstr_w(locale), type, buffer, len);
|
|
|
|
return GetLocaleInfoEx(locale, type, buffer, len);
|
|
|
|
}
|
2018-01-04 05:33:01 +01:00
|
|
|
#endif
|
2015-06-22 12:52:30 +02:00
|
|
|
|
2010-04-26 12:33:19 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* btowc(MSVCRT.@)
|
|
|
|
*/
|
|
|
|
MSVCRT_wint_t CDECL MSVCRT_btowc(int c)
|
|
|
|
{
|
|
|
|
unsigned char letter = c;
|
|
|
|
MSVCRT_wchar_t ret;
|
|
|
|
|
2020-01-28 23:08:13 +01:00
|
|
|
if(c == MSVCRT_EOF)
|
|
|
|
return MSVCRT_WEOF;
|
|
|
|
if(!get_locinfo()->lc_codepage)
|
|
|
|
return c & 255;
|
|
|
|
if(!MultiByteToWideChar(get_locinfo()->lc_codepage,
|
|
|
|
MB_ERR_INVALID_CHARS, (LPCSTR)&letter, 1, &ret, 1))
|
|
|
|
return MSVCRT_WEOF;
|
2010-04-26 12:33:19 +02:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-04-19 10:58:19 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* __crtGetStringTypeW(MSVCRT.@)
|
|
|
|
*
|
|
|
|
* This function was accepting different number of arguments in older
|
|
|
|
* versions of msvcrt.
|
|
|
|
*/
|
|
|
|
BOOL CDECL __crtGetStringTypeW(DWORD unk, DWORD type,
|
|
|
|
MSVCRT_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);
|
|
|
|
}
|
|
|
|
|
2003-06-04 22:24:56 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* localeconv (MSVCRT.@)
|
|
|
|
*/
|
2009-10-22 22:26:45 +02:00
|
|
|
struct MSVCRT_lconv * CDECL MSVCRT_localeconv(void)
|
|
|
|
{
|
2011-05-24 17:22:42 +02:00
|
|
|
return get_locinfo()->lconv;
|
2003-06-04 22:24:56 +02:00
|
|
|
}
|
2003-06-06 20:11:23 +02:00
|
|
|
|
2004-01-13 06:45:05 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* __lconv_init (MSVCRT.@)
|
|
|
|
*/
|
2010-06-11 01:57:53 +02:00
|
|
|
int CDECL __lconv_init(void)
|
2004-01-13 06:45:05 +01:00
|
|
|
{
|
2009-10-22 22:26:45 +02:00
|
|
|
/* this is used to make chars unsigned */
|
|
|
|
charmax = 255;
|
2010-06-11 01:57:53 +02:00
|
|
|
return 0;
|
2004-01-13 06:45:05 +01:00
|
|
|
}
|
2009-04-15 15:18:19 +02:00
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* ___lc_handle_func (MSVCRT.@)
|
|
|
|
*/
|
2011-05-26 11:40:04 +02:00
|
|
|
LCID* CDECL ___lc_handle_func(void)
|
2009-04-15 15:18:19 +02:00
|
|
|
{
|
2014-01-13 14:02:44 +01:00
|
|
|
return get_locinfo()->lc_handle;
|
2009-04-15 15:18:19 +02:00
|
|
|
}
|
|
|
|
|
2018-01-04 05:33:01 +01:00
|
|
|
#if _MSVCR_VER >= 110
|
2015-06-17 11:46:42 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* ___lc_locale_name_func (MSVCR110.@)
|
|
|
|
*/
|
|
|
|
MSVCRT_wchar_t** CDECL ___lc_locale_name_func(void)
|
|
|
|
{
|
|
|
|
return get_locinfo()->lc_name;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2009-04-15 15:18:19 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* ___lc_codepage_func (MSVCRT.@)
|
|
|
|
*/
|
2011-12-21 15:59:09 +01:00
|
|
|
unsigned int CDECL ___lc_codepage_func(void)
|
2009-04-15 15:18:19 +02:00
|
|
|
{
|
2014-01-13 14:02:44 +01:00
|
|
|
return get_locinfo()->lc_codepage;
|
2009-04-15 15:18:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* ___lc_collate_cp_func (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int CDECL ___lc_collate_cp_func(void)
|
|
|
|
{
|
2011-05-24 17:22:42 +02:00
|
|
|
return get_locinfo()->lc_collate_cp;
|
2009-04-15 15:18:19 +02:00
|
|
|
}
|
2010-04-08 10:24:25 +02:00
|
|
|
|
2011-05-24 17:22:42 +02:00
|
|
|
/* INTERNAL: frees MSVCRT_pthreadlocinfo struct */
|
|
|
|
void free_locinfo(MSVCRT_pthreadlocinfo locinfo)
|
2010-04-08 10:24:25 +02:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2011-05-24 17:22:42 +02:00
|
|
|
if(!locinfo)
|
2010-05-20 16:20:29 +02:00
|
|
|
return;
|
|
|
|
|
2011-12-06 12:47:54 +01:00
|
|
|
if(InterlockedDecrement(&locinfo->refcount))
|
|
|
|
return;
|
|
|
|
|
2010-04-08 10:24:25 +02:00
|
|
|
for(i=MSVCRT_LC_MIN+1; i<=MSVCRT_LC_MAX; i++) {
|
2011-05-24 17:22:42 +02:00
|
|
|
MSVCRT_free(locinfo->lc_category[i].locale);
|
|
|
|
MSVCRT_free(locinfo->lc_category[i].refcount);
|
2015-06-17 11:46:42 +02:00
|
|
|
#if _MSVCR_VER >= 110
|
|
|
|
MSVCRT_free(locinfo->lc_name[i]);
|
|
|
|
#endif
|
2010-04-08 10:24:25 +02:00
|
|
|
}
|
|
|
|
|
2011-05-24 17:22:42 +02:00
|
|
|
if(locinfo->lconv) {
|
|
|
|
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);
|
2016-05-04 14:29:50 +02:00
|
|
|
#if _MSVCR_VER >= 100
|
2014-11-21 20:36:46 +01:00
|
|
|
MSVCRT_free(locinfo->lconv->_W_decimal_point);
|
|
|
|
MSVCRT_free(locinfo->lconv->_W_thousands_sep);
|
|
|
|
MSVCRT_free(locinfo->lconv->_W_int_curr_symbol);
|
|
|
|
MSVCRT_free(locinfo->lconv->_W_currency_symbol);
|
|
|
|
MSVCRT_free(locinfo->lconv->_W_mon_decimal_point);
|
|
|
|
MSVCRT_free(locinfo->lconv->_W_mon_thousands_sep);
|
|
|
|
MSVCRT_free(locinfo->lconv->_W_positive_sign);
|
|
|
|
MSVCRT_free(locinfo->lconv->_W_negative_sign);
|
|
|
|
#endif
|
2010-04-08 10:24:25 +02:00
|
|
|
}
|
2011-05-24 17:22:42 +02:00
|
|
|
MSVCRT_free(locinfo->lconv_intl_refcount);
|
|
|
|
MSVCRT_free(locinfo->lconv_num_refcount);
|
|
|
|
MSVCRT_free(locinfo->lconv_mon_refcount);
|
|
|
|
MSVCRT_free(locinfo->lconv);
|
|
|
|
|
|
|
|
MSVCRT_free(locinfo->ctype1_refcount);
|
|
|
|
MSVCRT_free(locinfo->ctype1);
|
2010-04-08 10:24:25 +02:00
|
|
|
|
2011-05-24 17:22:42 +02:00
|
|
|
MSVCRT_free(locinfo->pclmap);
|
|
|
|
MSVCRT_free(locinfo->pcumap);
|
2010-04-08 10:24:25 +02:00
|
|
|
|
2019-12-04 16:22:14 +01:00
|
|
|
if(locinfo->lc_time_curr != &cloc_time_data)
|
|
|
|
MSVCRT_free(locinfo->lc_time_curr);
|
2011-12-07 13:48:22 +01:00
|
|
|
|
2011-05-24 17:22:42 +02:00
|
|
|
MSVCRT_free(locinfo);
|
|
|
|
}
|
2010-04-08 10:24:25 +02:00
|
|
|
|
2011-05-24 17:22:42 +02:00
|
|
|
/* INTERNAL: frees MSVCRT_pthreadmbcinfo struct */
|
|
|
|
void free_mbcinfo(MSVCRT_pthreadmbcinfo mbcinfo)
|
|
|
|
{
|
|
|
|
if(!mbcinfo)
|
|
|
|
return;
|
|
|
|
|
2011-12-06 12:47:54 +01:00
|
|
|
if(InterlockedDecrement(&mbcinfo->refcount))
|
|
|
|
return;
|
|
|
|
|
2011-05-24 17:22:42 +02:00
|
|
|
MSVCRT_free(mbcinfo);
|
|
|
|
}
|
|
|
|
|
2013-03-28 12:56:38 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _get_current_locale (MSVCRT.@)
|
|
|
|
*/
|
2011-12-06 12:47:54 +01:00
|
|
|
MSVCRT__locale_t CDECL MSVCRT__get_current_locale(void)
|
|
|
|
{
|
|
|
|
MSVCRT__locale_t loc = MSVCRT_malloc(sizeof(MSVCRT__locale_tstruct));
|
|
|
|
if(!loc)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
loc->locinfo = get_locinfo();
|
|
|
|
loc->mbcinfo = get_mbcinfo();
|
|
|
|
InterlockedIncrement(&loc->locinfo->refcount);
|
|
|
|
InterlockedIncrement(&loc->mbcinfo->refcount);
|
|
|
|
return loc;
|
|
|
|
}
|
|
|
|
|
2013-03-28 12:56:38 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _free_locale (MSVCRT.@)
|
|
|
|
*/
|
2011-05-24 17:22:42 +02:00
|
|
|
void CDECL MSVCRT__free_locale(MSVCRT__locale_t locale)
|
|
|
|
{
|
|
|
|
if (!locale)
|
|
|
|
return;
|
|
|
|
|
|
|
|
free_locinfo(locale->locinfo);
|
|
|
|
free_mbcinfo(locale->mbcinfo);
|
2010-04-08 10:24:25 +02:00
|
|
|
MSVCRT_free(locale);
|
|
|
|
}
|
|
|
|
|
2015-06-17 11:46:42 +02:00
|
|
|
#if _MSVCR_VER >= 110
|
2015-09-24 16:15:50 +02:00
|
|
|
static inline BOOL set_lc_locale_name(MSVCRT_pthreadlocinfo locinfo, int cat)
|
2015-06-17 11:46:42 +02:00
|
|
|
{
|
2015-09-24 16:15:50 +02:00
|
|
|
LCID lcid = locinfo->lc_handle[cat];
|
2015-06-17 11:46:42 +02:00
|
|
|
WCHAR buf[100];
|
|
|
|
int len;
|
|
|
|
|
|
|
|
len = GetLocaleInfoW(lcid, LOCALE_SISO639LANGNAME
|
|
|
|
|LOCALE_NOUSEROVERRIDE, buf, 100);
|
|
|
|
if(!len) return FALSE;
|
|
|
|
|
|
|
|
if(LocaleNameToLCID(buf, 0) != lcid)
|
|
|
|
len = LCIDToLocaleName(lcid, buf, 100, 0);
|
|
|
|
|
2015-09-24 16:15:50 +02:00
|
|
|
if(!len || !(locinfo->lc_name[cat] = MSVCRT_malloc(len*sizeof(MSVCRT_wchar_t))))
|
2015-06-17 11:46:42 +02:00
|
|
|
return FALSE;
|
|
|
|
|
2015-09-24 16:15:50 +02:00
|
|
|
memcpy(locinfo->lc_name[cat], buf, len*sizeof(MSVCRT_wchar_t));
|
2015-06-17 11:46:42 +02:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
#else
|
2015-09-24 16:15:50 +02:00
|
|
|
static inline BOOL set_lc_locale_name(MSVCRT_pthreadlocinfo locinfo, int cat)
|
2015-06-17 11:46:42 +02:00
|
|
|
{
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-09-24 16:16:16 +02:00
|
|
|
static inline BOOL category_needs_update(int cat, int user_cat,
|
|
|
|
MSVCRT_pthreadlocinfo locinfo, LCID lcid, unsigned short cp)
|
|
|
|
{
|
|
|
|
if(!locinfo) return TRUE;
|
|
|
|
if(user_cat!=cat && user_cat!=MSVCRT_LC_ALL) return FALSE;
|
|
|
|
return lcid!=locinfo->lc_handle[cat] || cp!=locinfo->lc_id[cat].wCodePage;
|
|
|
|
}
|
|
|
|
|
2019-12-04 15:29:55 +01:00
|
|
|
static MSVCRT___lc_time_data* create_time_data(LCID lcid)
|
2010-04-08 10:24:25 +02:00
|
|
|
{
|
2011-12-07 13:48:22 +01:00
|
|
|
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
|
|
|
|
};
|
2010-04-15 14:26:17 +02:00
|
|
|
|
2019-12-04 15:29:55 +01:00
|
|
|
MSVCRT___lc_time_data *cur;
|
|
|
|
int i, ret, size;
|
|
|
|
|
|
|
|
size = sizeof(MSVCRT___lc_time_data);
|
|
|
|
for(i=0; i<ARRAY_SIZE(time_data); i++) {
|
2019-12-04 16:22:14 +01:00
|
|
|
ret = GetLocaleInfoA(lcid, time_data[i], NULL, 0);
|
|
|
|
if(!ret)
|
|
|
|
return NULL;
|
|
|
|
size += ret;
|
2019-12-04 15:29:55 +01:00
|
|
|
|
2019-12-04 16:22:14 +01:00
|
|
|
ret = GetLocaleInfoW(lcid, time_data[i], NULL, 0);
|
|
|
|
if(!ret)
|
|
|
|
return NULL;
|
|
|
|
size += ret*sizeof(MSVCRT_wchar_t);
|
2019-12-04 15:29:55 +01:00
|
|
|
}
|
|
|
|
#if _MSVCR_VER >= 110
|
|
|
|
size += LCIDToLocaleName(lcid, NULL, 0, 0)*sizeof(MSVCRT_wchar_t);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
cur = MSVCRT_malloc(size);
|
|
|
|
if(!cur)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
for(i=0; i<ARRAY_SIZE(time_data); i++) {
|
|
|
|
cur->str.str[i] = &cur->data[ret];
|
2019-12-04 16:22:14 +01:00
|
|
|
ret += GetLocaleInfoA(lcid, time_data[i], &cur->data[ret], size-ret);
|
2019-12-04 15:29:55 +01:00
|
|
|
}
|
|
|
|
for(i=0; i<ARRAY_SIZE(time_data); i++) {
|
|
|
|
cur->wstr.wstr[i] = (MSVCRT_wchar_t*)&cur->data[ret];
|
2019-12-04 16:22:14 +01:00
|
|
|
ret += GetLocaleInfoW(lcid, time_data[i],
|
|
|
|
(MSVCRT_wchar_t*)&cur->data[ret], size-ret)*sizeof(MSVCRT_wchar_t);
|
2019-12-04 15:29:55 +01:00
|
|
|
}
|
|
|
|
#if _MSVCR_VER >= 110
|
|
|
|
cur->locname = (MSVCRT_wchar_t*)&cur->data[ret];
|
2019-12-04 15:30:45 +01:00
|
|
|
LCIDToLocaleName(lcid, (MSVCRT_wchar_t*)&cur->data[ret], (size-ret)/sizeof(MSVCRT_wchar_t), 0);
|
2019-12-04 15:29:55 +01:00
|
|
|
#else
|
|
|
|
cur->lcid = lcid;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return cur;
|
|
|
|
}
|
|
|
|
|
|
|
|
static MSVCRT_pthreadlocinfo create_locinfo(int category,
|
|
|
|
const char *locale, MSVCRT_pthreadlocinfo old_locinfo)
|
|
|
|
{
|
|
|
|
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=";
|
|
|
|
|
2015-09-24 16:15:54 +02:00
|
|
|
MSVCRT_pthreadlocinfo locinfo;
|
2019-12-04 15:29:55 +01:00
|
|
|
LCID lcid[6] = { 0 };
|
2012-12-18 11:38:33 +01:00
|
|
|
unsigned short cp[6] = { 0 };
|
2018-05-09 17:36:17 +02:00
|
|
|
const char *locale_name[6] = { 0 };
|
|
|
|
int locale_len[6] = { 0 };
|
2010-04-15 14:24:53 +02:00
|
|
|
char buf[256];
|
2018-05-09 17:36:17 +02:00
|
|
|
BOOL sname;
|
2016-05-04 14:29:50 +02:00
|
|
|
#if _MSVCR_VER >= 100
|
2014-11-21 20:36:46 +01:00
|
|
|
MSVCRT_wchar_t wbuf[256];
|
|
|
|
#endif
|
2019-12-04 15:29:55 +01:00
|
|
|
int i;
|
2010-04-08 10:24:25 +02:00
|
|
|
|
|
|
|
TRACE("(%d %s)\n", category, locale);
|
|
|
|
|
|
|
|
if(category<MSVCRT_LC_MIN || category>MSVCRT_LC_MAX || !locale)
|
|
|
|
return NULL;
|
|
|
|
|
2012-12-18 11:38:33 +01:00
|
|
|
if(locale[0]=='C' && !locale[1]) {
|
|
|
|
lcid[0] = 0;
|
|
|
|
cp[0] = CP_ACP;
|
|
|
|
} else if(!locale[0]) {
|
2010-04-15 14:26:17 +02:00
|
|
|
lcid[0] = GetSystemDefaultLCID();
|
2012-12-18 11:38:33 +01: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] == '_') {
|
2011-08-22 21:31:47 +02:00
|
|
|
const char *p;
|
2010-04-15 14:26:17 +02:00
|
|
|
|
|
|
|
while(1) {
|
|
|
|
locale += 3; /* LC_ */
|
|
|
|
if(!memcmp(locale, collate, sizeof(collate)-1)) {
|
|
|
|
i = MSVCRT_LC_COLLATE;
|
|
|
|
locale += sizeof(collate)-1;
|
|
|
|
} else if(!memcmp(locale, ctype, sizeof(ctype)-1)) {
|
|
|
|
i = MSVCRT_LC_CTYPE;
|
|
|
|
locale += sizeof(ctype)-1;
|
|
|
|
} else if(!memcmp(locale, monetary, sizeof(monetary)-1)) {
|
|
|
|
i = MSVCRT_LC_MONETARY;
|
|
|
|
locale += sizeof(monetary)-1;
|
|
|
|
} else if(!memcmp(locale, numeric, sizeof(numeric)-1)) {
|
|
|
|
i = MSVCRT_LC_NUMERIC;
|
|
|
|
locale += sizeof(numeric)-1;
|
|
|
|
} else if(!memcmp(locale, time, sizeof(time)-1)) {
|
|
|
|
i = MSVCRT_LC_TIME;
|
|
|
|
locale += sizeof(time)-1;
|
|
|
|
} else
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
p = strchr(locale, ';');
|
2012-12-18 11:38:33 +01:00
|
|
|
if(locale[0]=='C' && (locale[1]==';' || locale[1]=='\0')) {
|
2010-04-19 10:58:10 +02:00
|
|
|
lcid[i] = 0;
|
2012-12-18 11:38:33 +01:00
|
|
|
cp[i] = CP_ACP;
|
|
|
|
} else if(p) {
|
2010-04-15 14:26:17 +02:00
|
|
|
memcpy(buf, locale, p-locale);
|
2011-01-15 09:28:24 +01:00
|
|
|
buf[p-locale] = '\0';
|
2018-05-09 17:36:17 +02:00
|
|
|
lcid[i] = MSVCRT_locale_to_LCID(buf, &cp[i], &sname);
|
|
|
|
if(sname) {
|
|
|
|
locale_name[i] = locale;
|
|
|
|
locale_len[i] = p-locale;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
lcid[i] = MSVCRT_locale_to_LCID(locale, &cp[i], &sname);
|
|
|
|
if(sname) {
|
|
|
|
locale_name[i] = locale;
|
|
|
|
locale_len[i] = strlen(locale);
|
|
|
|
}
|
|
|
|
}
|
2010-04-15 14:26:17 +02:00
|
|
|
|
2010-04-19 10:58:10 +02:00
|
|
|
if(lcid[i] == -1)
|
2010-04-15 14:26:17 +02:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if(!p || *(p+1)!='L' || *(p+2)!='C' || *(p+3)!='_')
|
|
|
|
break;
|
|
|
|
|
2010-04-19 10:58:10 +02:00
|
|
|
locale = p+1;
|
2010-04-15 14:26:17 +02:00
|
|
|
}
|
2010-04-15 14:25:13 +02:00
|
|
|
} else {
|
2018-05-09 17:36:17 +02:00
|
|
|
lcid[0] = MSVCRT_locale_to_LCID(locale, &cp[0], &sname);
|
2010-04-19 10:58:10 +02:00
|
|
|
if(lcid[0] == -1)
|
2010-04-08 10:24:25 +02:00
|
|
|
return NULL;
|
2018-05-09 17:36:17 +02:00
|
|
|
if(sname) {
|
|
|
|
locale_name[0] = locale;
|
|
|
|
locale_len[0] = strlen(locale);
|
|
|
|
}
|
2010-04-08 10:24:25 +02:00
|
|
|
|
2012-12-18 11:38:33 +01:00
|
|
|
for(i=1; i<6; i++) {
|
2010-04-15 14:26:17 +02:00
|
|
|
lcid[i] = lcid[0];
|
2012-12-18 11:38:33 +01:00
|
|
|
cp[i] = cp[0];
|
2018-05-09 17:36:17 +02:00
|
|
|
locale_name[i] = locale_name[0];
|
|
|
|
locale_len[i] = locale_len[0];
|
2012-12-18 11:38:33 +01:00
|
|
|
}
|
2010-04-15 14:26:17 +02:00
|
|
|
}
|
|
|
|
|
2015-09-24 16:15:54 +02:00
|
|
|
locinfo = MSVCRT_malloc(sizeof(MSVCRT_threadlocinfo));
|
|
|
|
if(!locinfo)
|
2010-04-08 10:24:25 +02:00
|
|
|
return NULL;
|
|
|
|
|
2015-09-24 16:15:54 +02:00
|
|
|
memset(locinfo, 0, sizeof(MSVCRT_threadlocinfo));
|
|
|
|
locinfo->refcount = 1;
|
2010-04-08 10:24:25 +02:00
|
|
|
|
2015-09-24 16:15:54 +02:00
|
|
|
locinfo->lconv = MSVCRT_malloc(sizeof(struct MSVCRT_lconv));
|
|
|
|
if(!locinfo->lconv) {
|
|
|
|
free_locinfo(locinfo);
|
2010-04-08 10:24:25 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
2015-09-24 16:15:54 +02:00
|
|
|
memset(locinfo->lconv, 0, sizeof(struct MSVCRT_lconv));
|
2010-04-08 10:24:25 +02:00
|
|
|
|
2015-09-24 16:15:54 +02:00
|
|
|
locinfo->pclmap = MSVCRT_malloc(sizeof(char[256]));
|
|
|
|
locinfo->pcumap = MSVCRT_malloc(sizeof(char[256]));
|
|
|
|
if(!locinfo->pclmap || !locinfo->pcumap) {
|
|
|
|
free_locinfo(locinfo);
|
2010-04-08 10:24:25 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2018-05-09 17:36:17 +02:00
|
|
|
if(locale_name[MSVCRT_LC_COLLATE] &&
|
|
|
|
!init_category_name(locale_name[MSVCRT_LC_COLLATE],
|
|
|
|
locale_len[MSVCRT_LC_COLLATE], locinfo, MSVCRT_LC_COLLATE)) {
|
|
|
|
free_locinfo(locinfo);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2015-09-24 16:16:16 +02:00
|
|
|
if(!category_needs_update(MSVCRT_LC_COLLATE, category, old_locinfo,
|
|
|
|
lcid[MSVCRT_LC_COLLATE], cp[MSVCRT_LC_COLLATE])) {
|
|
|
|
locinfo->lc_handle[MSVCRT_LC_COLLATE] = old_locinfo->lc_handle[MSVCRT_LC_COLLATE];
|
|
|
|
locinfo->lc_id[MSVCRT_LC_COLLATE].wCodePage = old_locinfo->lc_id[MSVCRT_LC_COLLATE].wCodePage;
|
|
|
|
} else if(lcid[MSVCRT_LC_COLLATE] && (category==MSVCRT_LC_ALL || category==MSVCRT_LC_COLLATE)) {
|
2018-05-09 17:36:17 +02:00
|
|
|
if(!update_threadlocinfo_category(lcid[MSVCRT_LC_COLLATE],
|
2015-09-24 16:16:16 +02:00
|
|
|
cp[MSVCRT_LC_COLLATE], locinfo, MSVCRT_LC_COLLATE)) {
|
2015-09-24 16:15:54 +02:00
|
|
|
free_locinfo(locinfo);
|
2010-04-08 10:24:25 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
2011-12-06 12:48:09 +01:00
|
|
|
|
2015-09-24 16:15:54 +02:00
|
|
|
locinfo->lc_collate_cp = locinfo->lc_id[MSVCRT_LC_COLLATE].wCodePage;
|
2015-06-17 11:46:42 +02:00
|
|
|
|
2015-09-24 16:15:54 +02:00
|
|
|
if(!set_lc_locale_name(locinfo, MSVCRT_LC_COLLATE)) {
|
|
|
|
free_locinfo(locinfo);
|
2015-06-17 11:46:42 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
2010-04-15 14:24:53 +02:00
|
|
|
} else
|
2015-09-24 16:15:54 +02:00
|
|
|
locinfo->lc_category[MSVCRT_LC_COLLATE].locale = MSVCRT__strdup("C");
|
2010-04-08 10:24:25 +02:00
|
|
|
|
2018-05-09 17:36:17 +02:00
|
|
|
if(locale_name[MSVCRT_LC_CTYPE] &&
|
|
|
|
!init_category_name(locale_name[MSVCRT_LC_CTYPE],
|
|
|
|
locale_len[MSVCRT_LC_CTYPE], locinfo, MSVCRT_LC_CTYPE)) {
|
|
|
|
free_locinfo(locinfo);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2015-09-24 16:16:16 +02:00
|
|
|
if(!category_needs_update(MSVCRT_LC_CTYPE, category, old_locinfo,
|
|
|
|
lcid[MSVCRT_LC_CTYPE], cp[MSVCRT_LC_CTYPE])) {
|
|
|
|
locinfo->lc_handle[MSVCRT_LC_CTYPE] = old_locinfo->lc_handle[MSVCRT_LC_CTYPE];
|
|
|
|
locinfo->lc_id[MSVCRT_LC_CTYPE].wCodePage = old_locinfo->lc_id[MSVCRT_LC_CTYPE].wCodePage;
|
|
|
|
} else if(lcid[MSVCRT_LC_CTYPE] && (category==MSVCRT_LC_ALL || category==MSVCRT_LC_CTYPE)) {
|
2012-12-18 11:38:33 +01:00
|
|
|
CPINFO cp_info;
|
2011-03-31 17:07:58 +02:00
|
|
|
int j;
|
2010-04-08 10:24:25 +02:00
|
|
|
|
2018-05-09 17:36:17 +02:00
|
|
|
if(!update_threadlocinfo_category(lcid[MSVCRT_LC_CTYPE],
|
2015-09-24 16:16:16 +02:00
|
|
|
cp[MSVCRT_LC_CTYPE], locinfo, MSVCRT_LC_CTYPE)) {
|
2015-09-24 16:15:54 +02:00
|
|
|
free_locinfo(locinfo);
|
2010-04-08 10:24:25 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2015-09-24 16:15:54 +02:00
|
|
|
locinfo->lc_codepage = locinfo->lc_id[MSVCRT_LC_CTYPE].wCodePage;
|
|
|
|
locinfo->lc_clike = 1;
|
|
|
|
if(!GetCPInfo(locinfo->lc_codepage, &cp_info)) {
|
|
|
|
free_locinfo(locinfo);
|
2010-04-08 10:24:25 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
2015-09-24 16:15:54 +02:00
|
|
|
locinfo->mb_cur_max = cp_info.MaxCharSize;
|
2010-04-08 10:24:25 +02:00
|
|
|
|
2015-09-24 16:15:54 +02:00
|
|
|
locinfo->ctype1_refcount = MSVCRT_malloc(sizeof(int));
|
|
|
|
locinfo->ctype1 = MSVCRT_malloc(sizeof(short[257]));
|
|
|
|
if(!locinfo->ctype1_refcount || !locinfo->ctype1) {
|
|
|
|
free_locinfo(locinfo);
|
2010-04-08 10:24:25 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2015-09-24 16:15:54 +02:00
|
|
|
*locinfo->ctype1_refcount = 1;
|
|
|
|
locinfo->ctype1[0] = 0;
|
|
|
|
locinfo->pctype = locinfo->ctype1+1;
|
2010-04-08 10:24:25 +02:00
|
|
|
|
|
|
|
buf[1] = buf[2] = '\0';
|
|
|
|
for(i=1; i<257; i++) {
|
|
|
|
buf[0] = i-1;
|
|
|
|
|
2011-10-18 15:22:46 +02:00
|
|
|
/* builtin GetStringTypeA doesn't set output to 0 on invalid input */
|
2015-09-24 16:15:54 +02:00
|
|
|
locinfo->ctype1[i] = 0;
|
2011-10-18 15:22:46 +02:00
|
|
|
|
2010-04-15 14:26:17 +02:00
|
|
|
GetStringTypeA(lcid[MSVCRT_LC_CTYPE], CT_CTYPE1, buf,
|
2015-09-24 16:15:54 +02:00
|
|
|
1, locinfo->ctype1+i);
|
2010-04-08 10:24:25 +02:00
|
|
|
}
|
2011-03-31 17:07:58 +02:00
|
|
|
|
2012-12-18 11:38:33 +01: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++)
|
2015-09-24 16:15:54 +02:00
|
|
|
locinfo->ctype1[j+1] |= MSVCRT__LEADBYTE;
|
2015-06-17 11:46:42 +02:00
|
|
|
|
2015-09-24 16:15:54 +02:00
|
|
|
if(!set_lc_locale_name(locinfo, MSVCRT_LC_CTYPE)) {
|
|
|
|
free_locinfo(locinfo);
|
2015-06-17 11:46:42 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
2010-04-08 10:24:25 +02:00
|
|
|
|
2015-09-24 16:15:54 +02:00
|
|
|
for(i=0; i<256; i++) {
|
|
|
|
if(locinfo->pctype[i] & MSVCRT__LEADBYTE)
|
|
|
|
buf[i] = ' ';
|
|
|
|
else
|
|
|
|
buf[i] = i;
|
|
|
|
}
|
2010-04-08 10:24:25 +02:00
|
|
|
|
2011-06-03 15:28:46 +02:00
|
|
|
LCMapStringA(lcid[MSVCRT_LC_CTYPE], LCMAP_LOWERCASE, buf, 256,
|
2015-09-24 16:15:54 +02:00
|
|
|
(char*)locinfo->pclmap, 256);
|
2011-06-03 15:28:46 +02:00
|
|
|
LCMapStringA(lcid[MSVCRT_LC_CTYPE], LCMAP_UPPERCASE, buf, 256,
|
2015-09-24 16:15:54 +02:00
|
|
|
(char*)locinfo->pcumap, 256);
|
2011-06-03 15:28:46 +02:00
|
|
|
} else {
|
2015-09-24 16:15:54 +02:00
|
|
|
locinfo->lc_clike = 1;
|
|
|
|
locinfo->mb_cur_max = 1;
|
|
|
|
locinfo->pctype = MSVCRT__ctype+1;
|
|
|
|
locinfo->lc_category[MSVCRT_LC_CTYPE].locale = MSVCRT__strdup("C");
|
|
|
|
|
|
|
|
for(i=0; i<256; i++) {
|
|
|
|
if(locinfo->pctype[i] & MSVCRT__LEADBYTE)
|
|
|
|
buf[i] = ' ';
|
|
|
|
else
|
|
|
|
buf[i] = i;
|
|
|
|
}
|
|
|
|
|
2011-06-03 15:28:46 +02:00
|
|
|
for(i=0; i<256; i++) {
|
2015-09-24 16:15:54 +02:00
|
|
|
locinfo->pclmap[i] = (i>='A' && i<='Z' ? i-'A'+'a' : i);
|
|
|
|
locinfo->pcumap[i] = (i>='a' && i<='z' ? i-'a'+'A' : i);
|
2011-06-03 15:28:46 +02:00
|
|
|
}
|
|
|
|
}
|
2010-04-08 10:24:25 +02:00
|
|
|
|
2018-05-09 17:36:17 +02:00
|
|
|
if(locale_name[MSVCRT_LC_MONETARY] &&
|
|
|
|
!init_category_name(locale_name[MSVCRT_LC_MONETARY],
|
|
|
|
locale_len[MSVCRT_LC_MONETARY], locinfo, MSVCRT_LC_MONETARY)) {
|
|
|
|
free_locinfo(locinfo);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2015-09-24 16:16:16 +02:00
|
|
|
if(!category_needs_update(MSVCRT_LC_MONETARY, category, old_locinfo,
|
|
|
|
lcid[MSVCRT_LC_MONETARY], cp[MSVCRT_LC_MONETARY])) {
|
|
|
|
locinfo->lc_handle[MSVCRT_LC_MONETARY] = old_locinfo->lc_handle[MSVCRT_LC_MONETARY];
|
|
|
|
locinfo->lc_id[MSVCRT_LC_MONETARY].wCodePage = old_locinfo->lc_id[MSVCRT_LC_MONETARY].wCodePage;
|
|
|
|
} else if(lcid[MSVCRT_LC_MONETARY] && (category==MSVCRT_LC_ALL || category==MSVCRT_LC_MONETARY)) {
|
2018-05-09 17:36:17 +02:00
|
|
|
if(!update_threadlocinfo_category(lcid[MSVCRT_LC_MONETARY],
|
2015-09-24 16:16:16 +02:00
|
|
|
cp[MSVCRT_LC_MONETARY], locinfo, MSVCRT_LC_MONETARY)) {
|
2015-09-24 16:15:54 +02:00
|
|
|
free_locinfo(locinfo);
|
2010-04-08 10:24:25 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2015-09-24 16:15:54 +02:00
|
|
|
locinfo->lconv_intl_refcount = MSVCRT_malloc(sizeof(int));
|
|
|
|
locinfo->lconv_mon_refcount = MSVCRT_malloc(sizeof(int));
|
|
|
|
if(!locinfo->lconv_intl_refcount || !locinfo->lconv_mon_refcount) {
|
|
|
|
free_locinfo(locinfo);
|
2010-04-08 10:24:25 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2015-09-24 16:15:54 +02:00
|
|
|
*locinfo->lconv_intl_refcount = 1;
|
|
|
|
*locinfo->lconv_mon_refcount = 1;
|
2010-04-08 10:24:25 +02:00
|
|
|
|
2010-05-09 23:38:11 +02:00
|
|
|
i = GetLocaleInfoA(lcid[MSVCRT_LC_MONETARY], LOCALE_SINTLSYMBOL
|
|
|
|
|LOCALE_NOUSEROVERRIDE, buf, 256);
|
2015-09-24 16:15:54 +02:00
|
|
|
if(i && (locinfo->lconv->int_curr_symbol = MSVCRT_malloc(i)))
|
|
|
|
memcpy(locinfo->lconv->int_curr_symbol, buf, i);
|
2010-04-08 10:24:25 +02:00
|
|
|
else {
|
2015-09-24 16:15:54 +02:00
|
|
|
free_locinfo(locinfo);
|
2010-04-08 10:24:25 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2010-05-09 23:38:11 +02:00
|
|
|
i = GetLocaleInfoA(lcid[MSVCRT_LC_MONETARY], LOCALE_SCURRENCY
|
|
|
|
|LOCALE_NOUSEROVERRIDE, buf, 256);
|
2015-09-24 16:15:54 +02:00
|
|
|
if(i && (locinfo->lconv->currency_symbol = MSVCRT_malloc(i)))
|
|
|
|
memcpy(locinfo->lconv->currency_symbol, buf, i);
|
2010-04-08 10:24:25 +02:00
|
|
|
else {
|
2015-09-24 16:15:54 +02:00
|
|
|
free_locinfo(locinfo);
|
2010-04-08 10:24:25 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2010-05-09 23:38:11 +02:00
|
|
|
i = GetLocaleInfoA(lcid[MSVCRT_LC_MONETARY], LOCALE_SMONDECIMALSEP
|
|
|
|
|LOCALE_NOUSEROVERRIDE, buf, 256);
|
2015-09-24 16:15:54 +02:00
|
|
|
if(i && (locinfo->lconv->mon_decimal_point = MSVCRT_malloc(i)))
|
|
|
|
memcpy(locinfo->lconv->mon_decimal_point, buf, i);
|
2010-04-08 10:24:25 +02:00
|
|
|
else {
|
2015-09-24 16:15:54 +02:00
|
|
|
free_locinfo(locinfo);
|
2010-04-08 10:24:25 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2010-05-09 23:38:11 +02:00
|
|
|
i = GetLocaleInfoA(lcid[MSVCRT_LC_MONETARY], LOCALE_SMONTHOUSANDSEP
|
|
|
|
|LOCALE_NOUSEROVERRIDE, buf, 256);
|
2015-09-24 16:15:54 +02:00
|
|
|
if(i && (locinfo->lconv->mon_thousands_sep = MSVCRT_malloc(i)))
|
|
|
|
memcpy(locinfo->lconv->mon_thousands_sep, buf, i);
|
2010-04-08 10:24:25 +02:00
|
|
|
else {
|
2015-09-24 16:15:54 +02:00
|
|
|
free_locinfo(locinfo);
|
2010-04-08 10:24:25 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2010-05-09 23:38:11 +02:00
|
|
|
i = GetLocaleInfoA(lcid[MSVCRT_LC_MONETARY], LOCALE_SMONGROUPING
|
|
|
|
|LOCALE_NOUSEROVERRIDE, buf, 256);
|
2010-04-08 10:24:25 +02:00
|
|
|
if(i>1)
|
|
|
|
i = i/2 + (buf[i-2]=='0'?0:1);
|
2015-09-24 16:15:54 +02:00
|
|
|
if(i && (locinfo->lconv->mon_grouping = MSVCRT_malloc(i))) {
|
2010-04-08 10:24:25 +02:00
|
|
|
for(i=0; buf[i+1]==';'; i+=2)
|
2015-09-24 16:15:54 +02:00
|
|
|
locinfo->lconv->mon_grouping[i/2] = buf[i]-'0';
|
|
|
|
locinfo->lconv->mon_grouping[i/2] = buf[i]-'0';
|
2010-04-08 10:24:25 +02:00
|
|
|
if(buf[i] != '0')
|
2015-09-24 16:15:54 +02:00
|
|
|
locinfo->lconv->mon_grouping[i/2+1] = 127;
|
2010-04-08 10:24:25 +02:00
|
|
|
} else {
|
2015-09-24 16:15:54 +02:00
|
|
|
free_locinfo(locinfo);
|
2010-04-08 10:24:25 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2010-05-09 23:38:11 +02:00
|
|
|
i = GetLocaleInfoA(lcid[MSVCRT_LC_MONETARY], LOCALE_SPOSITIVESIGN
|
|
|
|
|LOCALE_NOUSEROVERRIDE, buf, 256);
|
2015-09-24 16:15:54 +02:00
|
|
|
if(i && (locinfo->lconv->positive_sign = MSVCRT_malloc(i)))
|
|
|
|
memcpy(locinfo->lconv->positive_sign, buf, i);
|
2010-04-08 10:24:25 +02:00
|
|
|
else {
|
2015-09-24 16:15:54 +02:00
|
|
|
free_locinfo(locinfo);
|
2010-04-08 10:24:25 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2010-05-09 23:38:11 +02:00
|
|
|
i = GetLocaleInfoA(lcid[MSVCRT_LC_MONETARY], LOCALE_SNEGATIVESIGN
|
|
|
|
|LOCALE_NOUSEROVERRIDE, buf, 256);
|
2015-09-24 16:15:54 +02:00
|
|
|
if(i && (locinfo->lconv->negative_sign = MSVCRT_malloc(i)))
|
|
|
|
memcpy(locinfo->lconv->negative_sign, buf, i);
|
2010-04-08 10:24:25 +02:00
|
|
|
else {
|
2015-09-24 16:15:54 +02:00
|
|
|
free_locinfo(locinfo);
|
2010-04-08 10:24:25 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2010-05-09 23:38:11 +02:00
|
|
|
if(GetLocaleInfoA(lcid[MSVCRT_LC_MONETARY], LOCALE_IINTLCURRDIGITS
|
|
|
|
|LOCALE_NOUSEROVERRIDE, buf, 256))
|
2015-09-24 16:15:54 +02:00
|
|
|
locinfo->lconv->int_frac_digits = atoi(buf);
|
2010-04-08 10:24:25 +02:00
|
|
|
else {
|
2015-09-24 16:15:54 +02:00
|
|
|
free_locinfo(locinfo);
|
2010-04-08 10:24:25 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2010-05-09 23:38:11 +02:00
|
|
|
if(GetLocaleInfoA(lcid[MSVCRT_LC_MONETARY], LOCALE_ICURRDIGITS
|
|
|
|
|LOCALE_NOUSEROVERRIDE, buf, 256))
|
2015-09-24 16:15:54 +02:00
|
|
|
locinfo->lconv->frac_digits = atoi(buf);
|
2010-04-08 10:24:25 +02:00
|
|
|
else {
|
2015-09-24 16:15:54 +02:00
|
|
|
free_locinfo(locinfo);
|
2010-04-08 10:24:25 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2010-05-09 23:38:11 +02:00
|
|
|
if(GetLocaleInfoA(lcid[MSVCRT_LC_MONETARY], LOCALE_IPOSSYMPRECEDES
|
|
|
|
|LOCALE_NOUSEROVERRIDE, buf, 256))
|
2015-09-24 16:15:54 +02:00
|
|
|
locinfo->lconv->p_cs_precedes = atoi(buf);
|
2010-04-08 10:24:25 +02:00
|
|
|
else {
|
2015-09-24 16:15:54 +02:00
|
|
|
free_locinfo(locinfo);
|
2010-04-08 10:24:25 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2010-05-09 23:38:11 +02:00
|
|
|
if(GetLocaleInfoA(lcid[MSVCRT_LC_MONETARY], LOCALE_IPOSSEPBYSPACE
|
|
|
|
|LOCALE_NOUSEROVERRIDE, buf, 256))
|
2015-09-24 16:15:54 +02:00
|
|
|
locinfo->lconv->p_sep_by_space = atoi(buf);
|
2010-04-08 10:24:25 +02:00
|
|
|
else {
|
2015-09-24 16:15:54 +02:00
|
|
|
free_locinfo(locinfo);
|
2010-04-08 10:24:25 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2010-05-09 23:38:11 +02:00
|
|
|
if(GetLocaleInfoA(lcid[MSVCRT_LC_MONETARY], LOCALE_INEGSYMPRECEDES
|
|
|
|
|LOCALE_NOUSEROVERRIDE, buf, 256))
|
2015-09-24 16:15:54 +02:00
|
|
|
locinfo->lconv->n_cs_precedes = atoi(buf);
|
2010-04-08 10:24:25 +02:00
|
|
|
else {
|
2015-09-24 16:15:54 +02:00
|
|
|
free_locinfo(locinfo);
|
2010-04-08 10:24:25 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2010-05-09 23:38:11 +02:00
|
|
|
if(GetLocaleInfoA(lcid[MSVCRT_LC_MONETARY], LOCALE_INEGSEPBYSPACE
|
|
|
|
|LOCALE_NOUSEROVERRIDE, buf, 256))
|
2015-09-24 16:15:54 +02:00
|
|
|
locinfo->lconv->n_sep_by_space = atoi(buf);
|
2010-04-08 10:24:25 +02:00
|
|
|
else {
|
2015-09-24 16:15:54 +02:00
|
|
|
free_locinfo(locinfo);
|
2010-04-08 10:24:25 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2010-05-09 23:38:11 +02:00
|
|
|
if(GetLocaleInfoA(lcid[MSVCRT_LC_MONETARY], LOCALE_IPOSSIGNPOSN
|
|
|
|
|LOCALE_NOUSEROVERRIDE, buf, 256))
|
2015-09-24 16:15:54 +02:00
|
|
|
locinfo->lconv->p_sign_posn = atoi(buf);
|
2010-04-08 10:24:25 +02:00
|
|
|
else {
|
2015-09-24 16:15:54 +02:00
|
|
|
free_locinfo(locinfo);
|
2010-04-08 10:24:25 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2010-05-09 23:38:11 +02:00
|
|
|
if(GetLocaleInfoA(lcid[MSVCRT_LC_MONETARY], LOCALE_INEGSIGNPOSN
|
|
|
|
|LOCALE_NOUSEROVERRIDE, buf, 256))
|
2015-09-24 16:15:54 +02:00
|
|
|
locinfo->lconv->n_sign_posn = atoi(buf);
|
2010-04-08 10:24:25 +02:00
|
|
|
else {
|
2015-09-24 16:15:54 +02:00
|
|
|
free_locinfo(locinfo);
|
2010-04-08 10:24:25 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
2014-11-21 20:36:46 +01:00
|
|
|
|
2016-05-04 14:29:50 +02:00
|
|
|
#if _MSVCR_VER >= 100
|
2014-11-21 20:36:46 +01:00
|
|
|
i = GetLocaleInfoW(lcid[MSVCRT_LC_MONETARY], LOCALE_SINTLSYMBOL
|
|
|
|
|LOCALE_NOUSEROVERRIDE, wbuf, 256);
|
2015-09-24 16:15:54 +02:00
|
|
|
if(i && (locinfo->lconv->_W_int_curr_symbol = MSVCRT_malloc(i * sizeof(MSVCRT_wchar_t))))
|
|
|
|
memcpy(locinfo->lconv->_W_int_curr_symbol, wbuf, i * sizeof(MSVCRT_wchar_t));
|
2014-11-21 20:36:46 +01:00
|
|
|
else {
|
2015-09-24 16:15:54 +02:00
|
|
|
free_locinfo(locinfo);
|
2014-11-21 20:36:46 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
i = GetLocaleInfoW(lcid[MSVCRT_LC_MONETARY], LOCALE_SCURRENCY
|
|
|
|
|LOCALE_NOUSEROVERRIDE, wbuf, 256);
|
2015-09-24 16:15:54 +02:00
|
|
|
if(i && (locinfo->lconv->_W_currency_symbol = MSVCRT_malloc(i * sizeof(MSVCRT_wchar_t))))
|
|
|
|
memcpy(locinfo->lconv->_W_currency_symbol, wbuf, i * sizeof(MSVCRT_wchar_t));
|
2014-11-21 20:36:46 +01:00
|
|
|
else {
|
2015-09-24 16:15:54 +02:00
|
|
|
free_locinfo(locinfo);
|
2014-11-21 20:36:46 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
i = GetLocaleInfoW(lcid[MSVCRT_LC_MONETARY], LOCALE_SMONDECIMALSEP
|
|
|
|
|LOCALE_NOUSEROVERRIDE, wbuf, 256);
|
2015-09-24 16:15:54 +02:00
|
|
|
if(i && (locinfo->lconv->_W_mon_decimal_point = MSVCRT_malloc(i * sizeof(MSVCRT_wchar_t))))
|
|
|
|
memcpy(locinfo->lconv->_W_mon_decimal_point, wbuf, i * sizeof(MSVCRT_wchar_t));
|
2014-11-21 20:36:46 +01:00
|
|
|
else {
|
2015-09-24 16:15:54 +02:00
|
|
|
free_locinfo(locinfo);
|
2014-11-21 20:36:46 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
i = GetLocaleInfoW(lcid[MSVCRT_LC_MONETARY], LOCALE_SMONTHOUSANDSEP
|
|
|
|
|LOCALE_NOUSEROVERRIDE, wbuf, 256);
|
2015-09-24 16:15:54 +02:00
|
|
|
if(i && (locinfo->lconv->_W_mon_thousands_sep = MSVCRT_malloc(i * sizeof(MSVCRT_wchar_t))))
|
|
|
|
memcpy(locinfo->lconv->_W_mon_thousands_sep, wbuf, i * sizeof(MSVCRT_wchar_t));
|
2014-11-21 20:36:46 +01:00
|
|
|
else {
|
2015-09-24 16:15:54 +02:00
|
|
|
free_locinfo(locinfo);
|
2014-11-21 20:36:46 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
i = GetLocaleInfoW(lcid[MSVCRT_LC_MONETARY], LOCALE_SPOSITIVESIGN
|
|
|
|
|LOCALE_NOUSEROVERRIDE, wbuf, 256);
|
2015-09-24 16:15:54 +02:00
|
|
|
if(i && (locinfo->lconv->_W_positive_sign = MSVCRT_malloc(i * sizeof(MSVCRT_wchar_t))))
|
|
|
|
memcpy(locinfo->lconv->_W_positive_sign, wbuf, i * sizeof(MSVCRT_wchar_t));
|
2014-11-21 20:36:46 +01:00
|
|
|
else {
|
2015-09-24 16:15:54 +02:00
|
|
|
free_locinfo(locinfo);
|
2014-11-21 20:36:46 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
i = GetLocaleInfoW(lcid[MSVCRT_LC_MONETARY], LOCALE_SNEGATIVESIGN
|
|
|
|
|LOCALE_NOUSEROVERRIDE, wbuf, 256);
|
2015-09-24 16:15:54 +02:00
|
|
|
if(i && (locinfo->lconv->_W_negative_sign = MSVCRT_malloc(i * sizeof(MSVCRT_wchar_t))))
|
|
|
|
memcpy(locinfo->lconv->_W_negative_sign, wbuf, i * sizeof(MSVCRT_wchar_t));
|
2014-11-21 20:36:46 +01:00
|
|
|
else {
|
2015-09-24 16:15:54 +02:00
|
|
|
free_locinfo(locinfo);
|
2014-11-21 20:36:46 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-09-24 16:15:54 +02:00
|
|
|
if(!set_lc_locale_name(locinfo, MSVCRT_LC_MONETARY)) {
|
|
|
|
free_locinfo(locinfo);
|
2015-06-17 11:46:42 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
2010-04-08 10:24:25 +02:00
|
|
|
} else {
|
2015-09-24 16:15:54 +02:00
|
|
|
locinfo->lconv->int_curr_symbol = MSVCRT_malloc(sizeof(char));
|
|
|
|
locinfo->lconv->currency_symbol = MSVCRT_malloc(sizeof(char));
|
|
|
|
locinfo->lconv->mon_decimal_point = MSVCRT_malloc(sizeof(char));
|
|
|
|
locinfo->lconv->mon_thousands_sep = MSVCRT_malloc(sizeof(char));
|
|
|
|
locinfo->lconv->mon_grouping = MSVCRT_malloc(sizeof(char));
|
|
|
|
locinfo->lconv->positive_sign = MSVCRT_malloc(sizeof(char));
|
|
|
|
locinfo->lconv->negative_sign = MSVCRT_malloc(sizeof(char));
|
|
|
|
|
|
|
|
if(!locinfo->lconv->int_curr_symbol || !locinfo->lconv->currency_symbol
|
|
|
|
|| !locinfo->lconv->mon_decimal_point || !locinfo->lconv->mon_thousands_sep
|
|
|
|
|| !locinfo->lconv->mon_grouping || !locinfo->lconv->positive_sign
|
|
|
|
|| !locinfo->lconv->negative_sign) {
|
|
|
|
free_locinfo(locinfo);
|
2010-04-08 10:24:25 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2015-09-24 16:15:54 +02:00
|
|
|
locinfo->lconv->int_curr_symbol[0] = '\0';
|
|
|
|
locinfo->lconv->currency_symbol[0] = '\0';
|
|
|
|
locinfo->lconv->mon_decimal_point[0] = '\0';
|
|
|
|
locinfo->lconv->mon_thousands_sep[0] = '\0';
|
|
|
|
locinfo->lconv->mon_grouping[0] = '\0';
|
|
|
|
locinfo->lconv->positive_sign[0] = '\0';
|
|
|
|
locinfo->lconv->negative_sign[0] = '\0';
|
2017-02-22 14:53:21 +01:00
|
|
|
locinfo->lconv->int_frac_digits = charmax;
|
|
|
|
locinfo->lconv->frac_digits = charmax;
|
|
|
|
locinfo->lconv->p_cs_precedes = charmax;
|
|
|
|
locinfo->lconv->p_sep_by_space = charmax;
|
|
|
|
locinfo->lconv->n_cs_precedes = charmax;
|
|
|
|
locinfo->lconv->n_sep_by_space = charmax;
|
|
|
|
locinfo->lconv->p_sign_posn = charmax;
|
|
|
|
locinfo->lconv->n_sign_posn = charmax;
|
2010-04-15 14:24:53 +02:00
|
|
|
|
2016-05-04 14:29:50 +02:00
|
|
|
#if _MSVCR_VER >= 100
|
2015-09-24 16:15:54 +02:00
|
|
|
locinfo->lconv->_W_int_curr_symbol = MSVCRT_malloc(sizeof(MSVCRT_wchar_t));
|
|
|
|
locinfo->lconv->_W_currency_symbol = MSVCRT_malloc(sizeof(MSVCRT_wchar_t));
|
|
|
|
locinfo->lconv->_W_mon_decimal_point = MSVCRT_malloc(sizeof(MSVCRT_wchar_t));
|
|
|
|
locinfo->lconv->_W_mon_thousands_sep = MSVCRT_malloc(sizeof(MSVCRT_wchar_t));
|
|
|
|
locinfo->lconv->_W_positive_sign = MSVCRT_malloc(sizeof(MSVCRT_wchar_t));
|
|
|
|
locinfo->lconv->_W_negative_sign = MSVCRT_malloc(sizeof(MSVCRT_wchar_t));
|
|
|
|
|
|
|
|
if(!locinfo->lconv->_W_int_curr_symbol || !locinfo->lconv->_W_currency_symbol
|
|
|
|
|| !locinfo->lconv->_W_mon_decimal_point || !locinfo->lconv->_W_mon_thousands_sep
|
|
|
|
|| !locinfo->lconv->positive_sign || !locinfo->lconv->negative_sign) {
|
|
|
|
free_locinfo(locinfo);
|
2014-11-21 20:36:46 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2015-09-24 16:15:54 +02:00
|
|
|
locinfo->lconv->_W_int_curr_symbol[0] = '\0';
|
|
|
|
locinfo->lconv->_W_currency_symbol[0] = '\0';
|
|
|
|
locinfo->lconv->_W_mon_decimal_point[0] = '\0';
|
|
|
|
locinfo->lconv->_W_mon_thousands_sep[0] = '\0';
|
|
|
|
locinfo->lconv->_W_positive_sign[0] = '\0';
|
|
|
|
locinfo->lconv->_W_negative_sign[0] = '\0';
|
2014-11-21 20:36:46 +01:00
|
|
|
#endif
|
|
|
|
|
2015-09-24 16:15:54 +02:00
|
|
|
locinfo->lc_category[MSVCRT_LC_MONETARY].locale = MSVCRT__strdup("C");
|
2010-04-08 10:24:25 +02:00
|
|
|
}
|
|
|
|
|
2018-05-09 17:36:17 +02:00
|
|
|
if(locale_name[MSVCRT_LC_NUMERIC] &&
|
|
|
|
!init_category_name(locale_name[MSVCRT_LC_NUMERIC],
|
|
|
|
locale_len[MSVCRT_LC_NUMERIC], locinfo, MSVCRT_LC_NUMERIC)) {
|
|
|
|
free_locinfo(locinfo);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2015-09-24 16:16:16 +02:00
|
|
|
if(!category_needs_update(MSVCRT_LC_NUMERIC, category, old_locinfo,
|
|
|
|
lcid[MSVCRT_LC_NUMERIC], cp[MSVCRT_LC_NUMERIC])) {
|
|
|
|
locinfo->lc_handle[MSVCRT_LC_NUMERIC] = old_locinfo->lc_handle[MSVCRT_LC_NUMERIC];
|
|
|
|
locinfo->lc_id[MSVCRT_LC_NUMERIC].wCodePage = old_locinfo->lc_id[MSVCRT_LC_NUMERIC].wCodePage;
|
|
|
|
} else if(lcid[MSVCRT_LC_NUMERIC] && (category==MSVCRT_LC_ALL || category==MSVCRT_LC_NUMERIC)) {
|
2018-05-09 17:36:17 +02:00
|
|
|
if(!update_threadlocinfo_category(lcid[MSVCRT_LC_NUMERIC],
|
2015-09-24 16:16:16 +02:00
|
|
|
cp[MSVCRT_LC_NUMERIC], locinfo, MSVCRT_LC_NUMERIC)) {
|
2015-09-24 16:15:54 +02:00
|
|
|
free_locinfo(locinfo);
|
2010-04-08 10:24:25 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2015-09-24 16:15:54 +02:00
|
|
|
if(!locinfo->lconv_intl_refcount)
|
|
|
|
locinfo->lconv_intl_refcount = MSVCRT_malloc(sizeof(int));
|
|
|
|
locinfo->lconv_num_refcount = MSVCRT_malloc(sizeof(int));
|
|
|
|
if(!locinfo->lconv_intl_refcount || !locinfo->lconv_num_refcount) {
|
|
|
|
free_locinfo(locinfo);
|
2010-04-08 10:24:25 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2015-09-24 16:15:54 +02:00
|
|
|
*locinfo->lconv_intl_refcount = 1;
|
|
|
|
*locinfo->lconv_num_refcount = 1;
|
2010-04-08 10:24:25 +02:00
|
|
|
|
2010-05-09 23:38:11 +02:00
|
|
|
i = GetLocaleInfoA(lcid[MSVCRT_LC_NUMERIC], LOCALE_SDECIMAL
|
|
|
|
|LOCALE_NOUSEROVERRIDE, buf, 256);
|
2015-09-24 16:15:54 +02:00
|
|
|
if(i && (locinfo->lconv->decimal_point = MSVCRT_malloc(i)))
|
|
|
|
memcpy(locinfo->lconv->decimal_point, buf, i);
|
2010-04-08 10:24:25 +02:00
|
|
|
else {
|
2015-09-24 16:15:54 +02:00
|
|
|
free_locinfo(locinfo);
|
2010-04-08 10:24:25 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2010-05-09 23:38:11 +02:00
|
|
|
i = GetLocaleInfoA(lcid[MSVCRT_LC_NUMERIC], LOCALE_STHOUSAND
|
|
|
|
|LOCALE_NOUSEROVERRIDE, buf, 256);
|
2015-09-24 16:15:54 +02:00
|
|
|
if(i && (locinfo->lconv->thousands_sep = MSVCRT_malloc(i)))
|
|
|
|
memcpy(locinfo->lconv->thousands_sep, buf, i);
|
2010-04-08 10:24:25 +02:00
|
|
|
else {
|
2015-09-24 16:15:54 +02:00
|
|
|
free_locinfo(locinfo);
|
2010-04-08 10:24:25 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2010-05-09 23:38:11 +02:00
|
|
|
i = GetLocaleInfoA(lcid[MSVCRT_LC_NUMERIC], LOCALE_SGROUPING
|
|
|
|
|LOCALE_NOUSEROVERRIDE, buf, 256);
|
2010-04-08 10:24:25 +02:00
|
|
|
if(i>1)
|
|
|
|
i = i/2 + (buf[i-2]=='0'?0:1);
|
2015-09-24 16:15:54 +02:00
|
|
|
if(i && (locinfo->lconv->grouping = MSVCRT_malloc(i))) {
|
2010-04-08 10:24:25 +02:00
|
|
|
for(i=0; buf[i+1]==';'; i+=2)
|
2015-09-24 16:15:54 +02:00
|
|
|
locinfo->lconv->grouping[i/2] = buf[i]-'0';
|
|
|
|
locinfo->lconv->grouping[i/2] = buf[i]-'0';
|
2010-04-08 10:24:25 +02:00
|
|
|
if(buf[i] != '0')
|
2015-09-24 16:15:54 +02:00
|
|
|
locinfo->lconv->grouping[i/2+1] = 127;
|
2010-04-08 10:24:25 +02:00
|
|
|
} else {
|
2015-09-24 16:15:54 +02:00
|
|
|
free_locinfo(locinfo);
|
2010-04-08 10:24:25 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
2014-11-21 20:36:46 +01:00
|
|
|
|
2016-05-04 14:29:50 +02:00
|
|
|
#if _MSVCR_VER >= 100
|
2014-11-21 20:36:46 +01:00
|
|
|
i = GetLocaleInfoW(lcid[MSVCRT_LC_NUMERIC], LOCALE_SDECIMAL
|
|
|
|
|LOCALE_NOUSEROVERRIDE, wbuf, 256);
|
2015-09-24 16:15:54 +02:00
|
|
|
if(i && (locinfo->lconv->_W_decimal_point = MSVCRT_malloc(i * sizeof(MSVCRT_wchar_t))))
|
|
|
|
memcpy(locinfo->lconv->_W_decimal_point, wbuf, i * sizeof(MSVCRT_wchar_t));
|
2014-11-21 20:36:46 +01:00
|
|
|
else {
|
2015-09-24 16:15:54 +02:00
|
|
|
free_locinfo(locinfo);
|
2014-11-21 20:36:46 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
i = GetLocaleInfoW(lcid[MSVCRT_LC_NUMERIC], LOCALE_STHOUSAND
|
|
|
|
|LOCALE_NOUSEROVERRIDE, wbuf, 256);
|
2015-09-24 16:15:54 +02:00
|
|
|
if(i && (locinfo->lconv->_W_thousands_sep = MSVCRT_malloc(i * sizeof(MSVCRT_wchar_t))))
|
|
|
|
memcpy(locinfo->lconv->_W_thousands_sep, wbuf, i * sizeof(MSVCRT_wchar_t));
|
2014-11-21 20:36:46 +01:00
|
|
|
else {
|
2015-09-24 16:15:54 +02:00
|
|
|
free_locinfo(locinfo);
|
2014-11-21 20:36:46 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-09-24 16:15:54 +02:00
|
|
|
if(!set_lc_locale_name(locinfo, MSVCRT_LC_NUMERIC)) {
|
|
|
|
free_locinfo(locinfo);
|
2015-06-17 11:46:42 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
2010-04-08 10:24:25 +02:00
|
|
|
} else {
|
2015-09-24 16:15:54 +02:00
|
|
|
locinfo->lconv->decimal_point = MSVCRT_malloc(sizeof(char[2]));
|
|
|
|
locinfo->lconv->thousands_sep = MSVCRT_malloc(sizeof(char));
|
|
|
|
locinfo->lconv->grouping = MSVCRT_malloc(sizeof(char));
|
|
|
|
if(!locinfo->lconv->decimal_point || !locinfo->lconv->thousands_sep
|
|
|
|
|| !locinfo->lconv->grouping) {
|
|
|
|
free_locinfo(locinfo);
|
2010-04-08 10:24:25 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2015-09-24 16:15:54 +02:00
|
|
|
locinfo->lconv->decimal_point[0] = '.';
|
|
|
|
locinfo->lconv->decimal_point[1] = '\0';
|
|
|
|
locinfo->lconv->thousands_sep[0] = '\0';
|
|
|
|
locinfo->lconv->grouping[0] = '\0';
|
2010-04-15 14:24:53 +02:00
|
|
|
|
2016-05-04 14:29:50 +02:00
|
|
|
#if _MSVCR_VER >= 100
|
2015-09-24 16:15:54 +02:00
|
|
|
locinfo->lconv->_W_decimal_point = MSVCRT_malloc(sizeof(MSVCRT_wchar_t[2]));
|
|
|
|
locinfo->lconv->_W_thousands_sep = MSVCRT_malloc(sizeof(MSVCRT_wchar_t));
|
2014-11-21 20:36:46 +01:00
|
|
|
|
2015-09-24 16:15:54 +02:00
|
|
|
if(!locinfo->lconv->_W_decimal_point || !locinfo->lconv->_W_thousands_sep) {
|
|
|
|
free_locinfo(locinfo);
|
2014-11-21 20:36:46 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2015-09-24 16:15:54 +02:00
|
|
|
locinfo->lconv->_W_decimal_point[0] = '.';
|
|
|
|
locinfo->lconv->_W_decimal_point[1] = '\0';
|
|
|
|
locinfo->lconv->_W_thousands_sep[0] = '\0';
|
2014-11-21 20:36:46 +01:00
|
|
|
#endif
|
|
|
|
|
2015-09-24 16:15:54 +02:00
|
|
|
locinfo->lc_category[MSVCRT_LC_NUMERIC].locale = MSVCRT__strdup("C");
|
2010-04-08 10:24:25 +02:00
|
|
|
}
|
|
|
|
|
2018-05-09 17:36:17 +02:00
|
|
|
if(locale_name[MSVCRT_LC_TIME] &&
|
|
|
|
!init_category_name(locale_name[MSVCRT_LC_TIME],
|
|
|
|
locale_len[MSVCRT_LC_TIME], locinfo, MSVCRT_LC_TIME)) {
|
|
|
|
free_locinfo(locinfo);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2015-09-24 16:16:16 +02:00
|
|
|
if(!category_needs_update(MSVCRT_LC_TIME, category, old_locinfo,
|
|
|
|
lcid[MSVCRT_LC_TIME], cp[MSVCRT_LC_TIME])) {
|
|
|
|
locinfo->lc_handle[MSVCRT_LC_TIME] = old_locinfo->lc_handle[MSVCRT_LC_TIME];
|
|
|
|
locinfo->lc_id[MSVCRT_LC_TIME].wCodePage = old_locinfo->lc_id[MSVCRT_LC_TIME].wCodePage;
|
2019-12-04 16:22:14 +01:00
|
|
|
} else 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], locinfo, MSVCRT_LC_TIME)) {
|
|
|
|
free_locinfo(locinfo);
|
|
|
|
return NULL;
|
|
|
|
}
|
2011-12-07 13:48:22 +01:00
|
|
|
|
2019-12-04 16:22:14 +01:00
|
|
|
if(!set_lc_locale_name(locinfo, MSVCRT_LC_TIME)) {
|
|
|
|
free_locinfo(locinfo);
|
|
|
|
return NULL;
|
|
|
|
}
|
2015-09-24 16:16:16 +02:00
|
|
|
|
2019-12-04 15:29:55 +01:00
|
|
|
locinfo->lc_time_curr = create_time_data(lcid[MSVCRT_LC_TIME]);
|
2015-09-24 16:16:16 +02:00
|
|
|
if(!locinfo->lc_time_curr) {
|
|
|
|
free_locinfo(locinfo);
|
|
|
|
return NULL;
|
|
|
|
}
|
2019-12-04 16:22:14 +01:00
|
|
|
} else {
|
|
|
|
locinfo->lc_category[MSVCRT_LC_TIME].locale = MSVCRT__strdup("C");
|
|
|
|
locinfo->lc_time_curr = &cloc_time_data;
|
2011-12-07 13:48:22 +01:00
|
|
|
}
|
|
|
|
|
2015-09-24 16:15:54 +02:00
|
|
|
return locinfo;
|
|
|
|
}
|
|
|
|
|
2016-06-14 20:28:12 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* _lock_locales (UCRTBASE.@)
|
|
|
|
*/
|
|
|
|
void CDECL _lock_locales(void)
|
|
|
|
{
|
2016-06-16 16:44:41 +02:00
|
|
|
_mlock(_SETLOCALE_LOCK);
|
2016-06-14 20:28:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _unlock_locales (UCRTBASE.@)
|
|
|
|
*/
|
|
|
|
void CDECL _unlock_locales(void)
|
|
|
|
{
|
2016-06-16 16:44:41 +02:00
|
|
|
_munlock(_SETLOCALE_LOCK);
|
2016-06-14 20:28:12 +02:00
|
|
|
}
|
|
|
|
|
2015-09-24 16:15:54 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* _create_locale (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
MSVCRT__locale_t CDECL MSVCRT__create_locale(int category, const char *locale)
|
|
|
|
{
|
|
|
|
MSVCRT__locale_t loc;
|
|
|
|
|
|
|
|
loc = MSVCRT_malloc(sizeof(MSVCRT__locale_tstruct));
|
|
|
|
if(!loc)
|
|
|
|
return NULL;
|
|
|
|
|
2015-09-24 16:16:16 +02:00
|
|
|
loc->locinfo = create_locinfo(category, locale, NULL);
|
2015-09-24 16:15:54 +02:00
|
|
|
if(!loc->locinfo) {
|
|
|
|
MSVCRT_free(loc);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
loc->mbcinfo = MSVCRT_malloc(sizeof(MSVCRT_threadmbcinfo));
|
|
|
|
if(!loc->mbcinfo) {
|
|
|
|
free_locinfo(loc->locinfo);
|
|
|
|
MSVCRT_free(loc);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
loc->mbcinfo->refcount = 1;
|
|
|
|
_setmbcp_l(loc->locinfo->lc_id[MSVCRT_LC_CTYPE].wCodePage,
|
|
|
|
loc->locinfo->lc_handle[MSVCRT_LC_CTYPE], loc->mbcinfo);
|
2010-04-08 10:24:25 +02:00
|
|
|
return loc;
|
|
|
|
}
|
2010-04-15 14:25:13 +02:00
|
|
|
|
2018-01-10 07:21:44 +01:00
|
|
|
#if _MSVCR_VER >= 110
|
2016-08-17 13:17:17 +02:00
|
|
|
/*********************************************************************
|
2018-01-10 07:21:44 +01:00
|
|
|
* _wcreate_locale (MSVCR110.@)
|
2016-08-17 13:17:17 +02:00
|
|
|
*/
|
|
|
|
MSVCRT__locale_t CDECL MSVCRT__wcreate_locale(int category, const MSVCRT_wchar_t *locale)
|
|
|
|
{
|
|
|
|
MSVCRT__locale_t loc;
|
|
|
|
MSVCRT_size_t len;
|
|
|
|
char *str;
|
|
|
|
|
|
|
|
if(category<MSVCRT_LC_MIN || category>MSVCRT_LC_MAX || !locale)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
len = MSVCRT_wcstombs(NULL, locale, 0);
|
|
|
|
if(len == -1)
|
|
|
|
return NULL;
|
|
|
|
if(!(str = MSVCRT_malloc(++len)))
|
|
|
|
return NULL;
|
|
|
|
MSVCRT_wcstombs(str, locale, len);
|
|
|
|
|
|
|
|
loc = MSVCRT__create_locale(category, str);
|
|
|
|
|
|
|
|
MSVCRT_free(str);
|
|
|
|
return loc;
|
|
|
|
}
|
2018-01-10 07:21:44 +01:00
|
|
|
#endif
|
2016-08-17 13:17:17 +02:00
|
|
|
|
2010-04-15 14:25:13 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* setlocale (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
char* CDECL MSVCRT_setlocale(int category, const char* locale)
|
|
|
|
{
|
2011-05-24 17:22:42 +02:00
|
|
|
MSVCRT_pthreadlocinfo locinfo = get_locinfo();
|
2015-09-24 16:16:02 +02:00
|
|
|
MSVCRT_pthreadlocinfo newlocinfo;
|
2010-04-15 14:25:13 +02:00
|
|
|
|
2010-04-19 10:58:51 +02:00
|
|
|
if(category<MSVCRT_LC_MIN || category>MSVCRT_LC_MAX)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if(!locale) {
|
|
|
|
if(category == MSVCRT_LC_ALL)
|
2011-05-24 17:22:42 +02:00
|
|
|
return construct_lc_all(locinfo);
|
2010-04-15 14:25:13 +02:00
|
|
|
|
2011-05-24 17:22:42 +02:00
|
|
|
return locinfo->lc_category[category].locale;
|
2010-04-15 14:25:13 +02:00
|
|
|
}
|
|
|
|
|
2015-09-24 16:16:16 +02:00
|
|
|
newlocinfo = create_locinfo(category, locale, locinfo);
|
2015-09-24 16:16:02 +02:00
|
|
|
if(!newlocinfo) {
|
2010-04-19 10:58:51 +02:00
|
|
|
WARN("%d %s failed\n", category, locale);
|
2010-04-15 14:25:13 +02:00
|
|
|
return NULL;
|
2010-04-19 10:58:51 +02:00
|
|
|
}
|
2010-04-15 14:25:13 +02:00
|
|
|
|
2016-06-16 16:44:41 +02:00
|
|
|
_lock_locales();
|
2010-04-15 14:25:13 +02:00
|
|
|
|
2019-01-23 11:59:05 +01:00
|
|
|
if(locale[0] != 'C' || locale[1] != '\0')
|
|
|
|
initial_locale = FALSE;
|
|
|
|
|
2015-09-24 16:16:16 +02:00
|
|
|
if(locinfo->lc_handle[MSVCRT_LC_COLLATE]!=newlocinfo->lc_handle[MSVCRT_LC_COLLATE]
|
|
|
|
|| locinfo->lc_id[MSVCRT_LC_COLLATE].wCodePage!=newlocinfo->lc_id[MSVCRT_LC_COLLATE].wCodePage) {
|
|
|
|
locinfo->lc_collate_cp = newlocinfo->lc_collate_cp;
|
|
|
|
locinfo->lc_handle[MSVCRT_LC_COLLATE] =
|
|
|
|
newlocinfo->lc_handle[MSVCRT_LC_COLLATE];
|
|
|
|
locinfo->lc_id[MSVCRT_LC_COLLATE] =
|
|
|
|
newlocinfo->lc_id[MSVCRT_LC_COLLATE];
|
2010-04-15 14:25:13 +02:00
|
|
|
|
2015-06-17 11:46:42 +02:00
|
|
|
#if _MSVCR_VER >= 110
|
2015-09-24 16:16:16 +02:00
|
|
|
swap_pointers((void**)&locinfo->lc_name[MSVCRT_LC_COLLATE],
|
|
|
|
(void**)&newlocinfo->lc_name[MSVCRT_LC_COLLATE]);
|
2015-06-17 11:46:42 +02:00
|
|
|
#endif
|
2015-09-24 16:16:16 +02:00
|
|
|
}
|
2018-05-09 17:36:17 +02:00
|
|
|
if(newlocinfo->lc_category[MSVCRT_LC_COLLATE].locale) {
|
|
|
|
swap_pointers((void**)&locinfo->lc_category[MSVCRT_LC_COLLATE].locale,
|
|
|
|
(void**)&newlocinfo->lc_category[MSVCRT_LC_COLLATE].locale);
|
|
|
|
swap_pointers((void**)&locinfo->lc_category[MSVCRT_LC_COLLATE].refcount,
|
|
|
|
(void**)&newlocinfo->lc_category[MSVCRT_LC_COLLATE].refcount);
|
|
|
|
}
|
2015-06-17 11:46:42 +02:00
|
|
|
|
2015-09-24 16:16:16 +02:00
|
|
|
if(locinfo->lc_handle[MSVCRT_LC_CTYPE]!=newlocinfo->lc_handle[MSVCRT_LC_CTYPE]
|
|
|
|
|| locinfo->lc_id[MSVCRT_LC_CTYPE].wCodePage!=newlocinfo->lc_id[MSVCRT_LC_CTYPE].wCodePage) {
|
|
|
|
locinfo->lc_handle[MSVCRT_LC_CTYPE] =
|
|
|
|
newlocinfo->lc_handle[MSVCRT_LC_CTYPE];
|
|
|
|
locinfo->lc_id[MSVCRT_LC_CTYPE] =
|
|
|
|
newlocinfo->lc_id[MSVCRT_LC_CTYPE];
|
|
|
|
|
|
|
|
locinfo->lc_codepage = newlocinfo->lc_codepage;
|
|
|
|
locinfo->lc_clike = newlocinfo->lc_clike;
|
|
|
|
locinfo->mb_cur_max = newlocinfo->mb_cur_max;
|
|
|
|
|
|
|
|
swap_pointers((void**)&locinfo->ctype1_refcount,
|
|
|
|
(void**)&newlocinfo->ctype1_refcount);
|
|
|
|
swap_pointers((void**)&locinfo->ctype1, (void**)&newlocinfo->ctype1);
|
|
|
|
swap_pointers((void**)&locinfo->pctype, (void**)&newlocinfo->pctype);
|
|
|
|
swap_pointers((void**)&locinfo->pclmap, (void**)&newlocinfo->pclmap);
|
|
|
|
swap_pointers((void**)&locinfo->pcumap, (void**)&newlocinfo->pcumap);
|
2010-04-15 14:25:13 +02:00
|
|
|
|
2015-06-17 11:46:42 +02:00
|
|
|
#if _MSVCR_VER >= 110
|
2015-09-24 16:16:16 +02:00
|
|
|
swap_pointers((void**)&locinfo->lc_name[MSVCRT_LC_CTYPE],
|
|
|
|
(void**)&newlocinfo->lc_name[MSVCRT_LC_CTYPE]);
|
2015-06-17 11:46:42 +02:00
|
|
|
#endif
|
2015-09-24 16:16:16 +02:00
|
|
|
}
|
2018-05-09 17:36:17 +02:00
|
|
|
if(newlocinfo->lc_category[MSVCRT_LC_CTYPE].locale) {
|
|
|
|
swap_pointers((void**)&locinfo->lc_category[MSVCRT_LC_CTYPE].locale,
|
|
|
|
(void**)&newlocinfo->lc_category[MSVCRT_LC_CTYPE].locale);
|
|
|
|
swap_pointers((void**)&locinfo->lc_category[MSVCRT_LC_CTYPE].refcount,
|
|
|
|
(void**)&newlocinfo->lc_category[MSVCRT_LC_CTYPE].refcount);
|
|
|
|
}
|
2015-06-17 11:46:42 +02:00
|
|
|
|
2015-09-24 16:16:16 +02:00
|
|
|
if(locinfo->lc_handle[MSVCRT_LC_MONETARY]!=newlocinfo->lc_handle[MSVCRT_LC_MONETARY]
|
|
|
|
|| locinfo->lc_id[MSVCRT_LC_MONETARY].wCodePage!=newlocinfo->lc_id[MSVCRT_LC_MONETARY].wCodePage) {
|
|
|
|
locinfo->lc_handle[MSVCRT_LC_MONETARY] =
|
|
|
|
newlocinfo->lc_handle[MSVCRT_LC_MONETARY];
|
|
|
|
locinfo->lc_id[MSVCRT_LC_MONETARY] =
|
|
|
|
newlocinfo->lc_id[MSVCRT_LC_MONETARY];
|
|
|
|
|
|
|
|
swap_pointers((void**)&locinfo->lconv->int_curr_symbol,
|
|
|
|
(void**)&newlocinfo->lconv->int_curr_symbol);
|
|
|
|
swap_pointers((void**)&locinfo->lconv->currency_symbol,
|
|
|
|
(void**)&newlocinfo->lconv->currency_symbol);
|
|
|
|
swap_pointers((void**)&locinfo->lconv->mon_decimal_point,
|
|
|
|
(void**)&newlocinfo->lconv->mon_decimal_point);
|
|
|
|
swap_pointers((void**)&locinfo->lconv->mon_thousands_sep,
|
|
|
|
(void**)&newlocinfo->lconv->mon_thousands_sep);
|
|
|
|
swap_pointers((void**)&locinfo->lconv->mon_grouping,
|
|
|
|
(void**)&newlocinfo->lconv->mon_grouping);
|
|
|
|
swap_pointers((void**)&locinfo->lconv->positive_sign,
|
|
|
|
(void**)&newlocinfo->lconv->positive_sign);
|
|
|
|
swap_pointers((void**)&locinfo->lconv->negative_sign,
|
|
|
|
(void**)&newlocinfo->lconv->negative_sign);
|
2014-11-21 20:36:46 +01:00
|
|
|
|
2016-05-04 14:29:50 +02:00
|
|
|
#if _MSVCR_VER >= 100
|
2015-09-24 16:16:16 +02:00
|
|
|
swap_pointers((void**)&locinfo->lconv->_W_int_curr_symbol,
|
|
|
|
(void**)&newlocinfo->lconv->_W_int_curr_symbol);
|
|
|
|
swap_pointers((void**)&locinfo->lconv->_W_currency_symbol,
|
|
|
|
(void**)&newlocinfo->lconv->_W_currency_symbol);
|
|
|
|
swap_pointers((void**)&locinfo->lconv->_W_mon_decimal_point,
|
|
|
|
(void**)&newlocinfo->lconv->_W_mon_decimal_point);
|
|
|
|
swap_pointers((void**)&locinfo->lconv->_W_mon_thousands_sep,
|
|
|
|
(void**)&newlocinfo->lconv->_W_mon_thousands_sep);
|
|
|
|
swap_pointers((void**)&locinfo->lconv->_W_positive_sign,
|
|
|
|
(void**)&newlocinfo->lconv->_W_positive_sign);
|
|
|
|
swap_pointers((void**)&locinfo->lconv->_W_negative_sign,
|
|
|
|
(void**)&newlocinfo->lconv->_W_negative_sign);
|
2014-11-21 20:36:46 +01:00
|
|
|
#endif
|
|
|
|
|
2015-09-24 16:16:16 +02:00
|
|
|
locinfo->lconv->int_frac_digits = newlocinfo->lconv->int_frac_digits;
|
|
|
|
locinfo->lconv->frac_digits = newlocinfo->lconv->frac_digits;
|
|
|
|
locinfo->lconv->p_cs_precedes = newlocinfo->lconv->p_cs_precedes;
|
|
|
|
locinfo->lconv->p_sep_by_space = newlocinfo->lconv->p_sep_by_space;
|
|
|
|
locinfo->lconv->n_cs_precedes = newlocinfo->lconv->n_cs_precedes;
|
|
|
|
locinfo->lconv->n_sep_by_space = newlocinfo->lconv->n_sep_by_space;
|
|
|
|
locinfo->lconv->p_sign_posn = newlocinfo->lconv->p_sign_posn;
|
|
|
|
locinfo->lconv->n_sign_posn = newlocinfo->lconv->n_sign_posn;
|
2010-04-15 14:25:13 +02:00
|
|
|
|
2015-06-17 11:46:42 +02:00
|
|
|
#if _MSVCR_VER >= 110
|
2015-09-24 16:16:16 +02:00
|
|
|
swap_pointers((void**)&locinfo->lc_name[MSVCRT_LC_MONETARY],
|
|
|
|
(void**)&newlocinfo->lc_name[MSVCRT_LC_MONETARY]);
|
2015-06-17 11:46:42 +02:00
|
|
|
#endif
|
2015-09-24 16:16:16 +02:00
|
|
|
}
|
2018-05-09 17:36:17 +02:00
|
|
|
if(newlocinfo->lc_category[MSVCRT_LC_MONETARY].locale) {
|
|
|
|
swap_pointers((void**)&locinfo->lc_category[MSVCRT_LC_MONETARY].locale,
|
|
|
|
(void**)&newlocinfo->lc_category[MSVCRT_LC_MONETARY].locale);
|
|
|
|
swap_pointers((void**)&locinfo->lc_category[MSVCRT_LC_MONETARY].refcount,
|
|
|
|
(void**)&newlocinfo->lc_category[MSVCRT_LC_MONETARY].refcount);
|
|
|
|
}
|
2015-06-17 11:46:42 +02:00
|
|
|
|
2015-09-24 16:16:16 +02:00
|
|
|
if(locinfo->lc_handle[MSVCRT_LC_NUMERIC]!=newlocinfo->lc_handle[MSVCRT_LC_NUMERIC]
|
|
|
|
|| locinfo->lc_id[MSVCRT_LC_NUMERIC].wCodePage!=newlocinfo->lc_id[MSVCRT_LC_NUMERIC].wCodePage) {
|
|
|
|
locinfo->lc_handle[MSVCRT_LC_NUMERIC] =
|
|
|
|
newlocinfo->lc_handle[MSVCRT_LC_NUMERIC];
|
|
|
|
locinfo->lc_id[MSVCRT_LC_NUMERIC] =
|
|
|
|
newlocinfo->lc_id[MSVCRT_LC_NUMERIC];
|
|
|
|
|
|
|
|
swap_pointers((void**)&locinfo->lconv->decimal_point,
|
|
|
|
(void**)&newlocinfo->lconv->decimal_point);
|
|
|
|
swap_pointers((void**)&locinfo->lconv->thousands_sep,
|
|
|
|
(void**)&newlocinfo->lconv->thousands_sep);
|
|
|
|
swap_pointers((void**)&locinfo->lconv->grouping,
|
|
|
|
(void**)&newlocinfo->lconv->grouping);
|
2010-04-15 14:25:13 +02:00
|
|
|
|
2016-05-04 14:29:50 +02:00
|
|
|
#if _MSVCR_VER >= 100
|
2015-09-24 16:16:16 +02:00
|
|
|
swap_pointers((void**)&locinfo->lconv->_W_decimal_point,
|
|
|
|
(void**)&newlocinfo->lconv->_W_decimal_point);
|
|
|
|
swap_pointers((void**)&locinfo->lconv->_W_thousands_sep,
|
|
|
|
(void**)&newlocinfo->lconv->_W_thousands_sep);
|
2014-11-21 20:36:46 +01:00
|
|
|
#endif
|
|
|
|
|
2015-06-17 11:46:42 +02:00
|
|
|
#if _MSVCR_VER >= 110
|
2015-09-24 16:16:16 +02:00
|
|
|
swap_pointers((void**)&locinfo->lc_name[MSVCRT_LC_NUMERIC],
|
|
|
|
(void**)&newlocinfo->lc_name[MSVCRT_LC_NUMERIC]);
|
2015-06-17 11:46:42 +02:00
|
|
|
#endif
|
2015-09-24 16:16:16 +02:00
|
|
|
}
|
2018-05-09 17:36:17 +02:00
|
|
|
if(newlocinfo->lc_category[MSVCRT_LC_NUMERIC].locale) {
|
|
|
|
swap_pointers((void**)&locinfo->lc_category[MSVCRT_LC_NUMERIC].locale,
|
|
|
|
(void**)&newlocinfo->lc_category[MSVCRT_LC_NUMERIC].locale);
|
|
|
|
swap_pointers((void**)&locinfo->lc_category[MSVCRT_LC_NUMERIC].refcount,
|
|
|
|
(void**)&newlocinfo->lc_category[MSVCRT_LC_NUMERIC].refcount);
|
|
|
|
}
|
2015-06-17 11:46:42 +02:00
|
|
|
|
2015-09-24 16:16:16 +02:00
|
|
|
if(locinfo->lc_handle[MSVCRT_LC_TIME]!=newlocinfo->lc_handle[MSVCRT_LC_TIME]
|
|
|
|
|| locinfo->lc_id[MSVCRT_LC_TIME].wCodePage!=newlocinfo->lc_id[MSVCRT_LC_TIME].wCodePage) {
|
|
|
|
locinfo->lc_handle[MSVCRT_LC_TIME] =
|
|
|
|
newlocinfo->lc_handle[MSVCRT_LC_TIME];
|
|
|
|
locinfo->lc_id[MSVCRT_LC_TIME] =
|
|
|
|
newlocinfo->lc_id[MSVCRT_LC_TIME];
|
|
|
|
swap_pointers((void**)&locinfo->lc_time_curr,
|
|
|
|
(void**)&newlocinfo->lc_time_curr);
|
2010-04-15 14:25:13 +02:00
|
|
|
|
2015-06-17 11:46:42 +02:00
|
|
|
#if _MSVCR_VER >= 110
|
2015-09-24 16:16:16 +02:00
|
|
|
swap_pointers((void**)&locinfo->lc_name[MSVCRT_LC_TIME],
|
|
|
|
(void**)&newlocinfo->lc_name[MSVCRT_LC_TIME]);
|
2015-06-17 11:46:42 +02:00
|
|
|
#endif
|
2010-04-15 14:25:13 +02:00
|
|
|
}
|
2018-05-09 17:36:17 +02:00
|
|
|
if(newlocinfo->lc_category[MSVCRT_LC_TIME].locale) {
|
|
|
|
swap_pointers((void**)&locinfo->lc_category[MSVCRT_LC_TIME].locale,
|
|
|
|
(void**)&newlocinfo->lc_category[MSVCRT_LC_TIME].locale);
|
|
|
|
swap_pointers((void**)&locinfo->lc_category[MSVCRT_LC_TIME].refcount,
|
|
|
|
(void**)&newlocinfo->lc_category[MSVCRT_LC_TIME].refcount);
|
|
|
|
}
|
2010-04-15 14:25:13 +02:00
|
|
|
|
2015-09-24 16:16:02 +02:00
|
|
|
free_locinfo(newlocinfo);
|
2016-06-16 16:44:41 +02:00
|
|
|
_unlock_locales();
|
2010-04-15 14:25:13 +02:00
|
|
|
|
2011-05-24 17:22:42 +02:00
|
|
|
if(locinfo == MSVCRT_locale->locinfo) {
|
2011-05-26 11:40:04 +02:00
|
|
|
int i;
|
|
|
|
|
2011-05-24 17:22:42 +02:00
|
|
|
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;
|
2011-05-26 11:40:04 +02:00
|
|
|
for(i=MSVCRT_LC_MIN; i<=MSVCRT_LC_MAX; i++)
|
|
|
|
MSVCRT___lc_handle[i] = MSVCRT_locale->locinfo->lc_handle[i];
|
2010-04-15 14:26:33 +02:00
|
|
|
}
|
2010-04-15 14:25:13 +02:00
|
|
|
|
|
|
|
if(category == MSVCRT_LC_ALL)
|
2011-05-24 17:22:42 +02:00
|
|
|
return construct_lc_all(locinfo);
|
2010-04-15 14:25:13 +02:00
|
|
|
|
2011-05-24 17:22:42 +02:00
|
|
|
return locinfo->lc_category[category].locale;
|
2010-04-15 14:25:13 +02:00
|
|
|
}
|
2011-05-24 17:22:23 +02:00
|
|
|
|
2013-08-29 12:07:03 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* _wsetlocale (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
MSVCRT_wchar_t* CDECL MSVCRT__wsetlocale(int category, const MSVCRT_wchar_t* wlocale)
|
|
|
|
{
|
|
|
|
static MSVCRT_wchar_t current_lc_all[MAX_LOCALE_LENGTH];
|
|
|
|
|
|
|
|
char *locale = NULL;
|
|
|
|
const char *ret;
|
|
|
|
MSVCRT_size_t len;
|
|
|
|
|
|
|
|
if(wlocale) {
|
|
|
|
len = MSVCRT_wcstombs(NULL, wlocale, 0);
|
|
|
|
if(len == -1)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
locale = MSVCRT_malloc(++len);
|
|
|
|
if(!locale)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
MSVCRT_wcstombs(locale, wlocale, len);
|
|
|
|
}
|
|
|
|
|
2016-06-16 16:44:41 +02:00
|
|
|
_lock_locales();
|
2013-08-29 12:07:03 +02:00
|
|
|
ret = MSVCRT_setlocale(category, locale);
|
|
|
|
MSVCRT_free(locale);
|
|
|
|
|
|
|
|
if(ret && MSVCRT_mbstowcs(current_lc_all, ret, MAX_LOCALE_LENGTH)==-1)
|
|
|
|
ret = NULL;
|
|
|
|
|
2016-06-16 16:44:41 +02:00
|
|
|
_unlock_locales();
|
2013-08-29 12:07:03 +02:00
|
|
|
return ret ? current_lc_all : NULL;
|
|
|
|
}
|
|
|
|
|
2018-01-04 05:33:01 +01:00
|
|
|
#if _MSVCR_VER >= 80
|
2014-04-21 14:32:40 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* _configthreadlocale (MSVCR80.@)
|
|
|
|
*/
|
2011-05-24 17:22:23 +02:00
|
|
|
int CDECL _configthreadlocale(int type)
|
|
|
|
{
|
|
|
|
thread_data_t *data = msvcrt_get_thread_data();
|
2011-05-24 17:22:42 +02:00
|
|
|
MSVCRT__locale_t locale;
|
2011-05-24 17:22:23 +02:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
if(!data)
|
|
|
|
return -1;
|
|
|
|
|
2011-05-24 17:22:42 +02:00
|
|
|
ret = (data->have_locale ? MSVCRT__ENABLE_PER_THREAD_LOCALE : MSVCRT__DISABLE_PER_THREAD_LOCALE);
|
2011-05-24 17:22:23 +02:00
|
|
|
|
|
|
|
if(type == MSVCRT__ENABLE_PER_THREAD_LOCALE) {
|
2011-05-24 17:22:42 +02:00
|
|
|
if(!data->have_locale) {
|
2011-05-24 17:22:23 +02:00
|
|
|
/* Copy current global locale */
|
2011-05-24 17:22:42 +02:00
|
|
|
locale = MSVCRT__create_locale(MSVCRT_LC_ALL, MSVCRT_setlocale(MSVCRT_LC_ALL, NULL));
|
|
|
|
if(!locale)
|
2011-05-24 17:22:23 +02:00
|
|
|
return -1;
|
2011-05-24 17:22:42 +02:00
|
|
|
|
|
|
|
data->locinfo = locale->locinfo;
|
|
|
|
data->mbcinfo = locale->mbcinfo;
|
|
|
|
data->have_locale = TRUE;
|
|
|
|
MSVCRT_free(locale);
|
2011-05-24 17:22:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(type == MSVCRT__DISABLE_PER_THREAD_LOCALE) {
|
2011-05-24 17:22:42 +02:00
|
|
|
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;
|
2011-05-24 17:22:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!type)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
2018-01-04 05:33:01 +01:00
|
|
|
#endif
|
2011-05-26 11:40:04 +02:00
|
|
|
|
|
|
|
BOOL msvcrt_init_locale(void)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2016-06-16 16:44:41 +02:00
|
|
|
_lock_locales();
|
2011-05-26 11:40:04 +02:00
|
|
|
MSVCRT_locale = MSVCRT__create_locale(0, "C");
|
2016-06-16 16:44:41 +02:00
|
|
|
_unlock_locales();
|
2011-05-26 11:40:04 +02:00
|
|
|
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];
|
2011-10-12 11:54:53 +02:00
|
|
|
_setmbcp(_MB_CP_ANSI);
|
2011-05-26 11:40:04 +02:00
|
|
|
return TRUE;
|
|
|
|
}
|
2019-03-21 16:30:21 +01:00
|
|
|
|
|
|
|
#if _MSVCR_VER >= 120
|
|
|
|
/*********************************************************************
|
|
|
|
* wctrans (MSVCR120.@)
|
|
|
|
*/
|
|
|
|
MSVCRT_wctrans_t CDECL MSVCR120_wctrans(const char *property)
|
|
|
|
{
|
|
|
|
static const char str_tolower[] = "tolower";
|
|
|
|
static const char str_toupper[] = "toupper";
|
|
|
|
|
|
|
|
if(!strcmp(property, str_tolower))
|
|
|
|
return 2;
|
|
|
|
if(!strcmp(property, str_toupper))
|
|
|
|
return 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* towctrans (MSVCR120.@)
|
|
|
|
*/
|
|
|
|
MSVCRT_wint_t CDECL MSVCR120_towctrans(MSVCRT_wint_t c, MSVCRT_wctrans_t category)
|
|
|
|
{
|
|
|
|
if(category == 1)
|
|
|
|
return MSVCRT__towupper_l(c, NULL);
|
|
|
|
return MSVCRT__towlower_l(c, NULL);
|
|
|
|
}
|
|
|
|
#endif
|