libs/libc/locale/lib_localeconv.c and lib_setlocale.c: Make localeconv() and setlocale() more compliance with spec:

1. localeconvi() should return C locale not NULL by default
2. setlocale() should return "C" if new locale equals NULL
This commit is contained in:
Xiang Xiao 2019-11-18 11:41:32 -06:00 committed by Gregory Nutt
parent 111fc0c83e
commit fb31d38394
2 changed files with 35 additions and 10 deletions

View File

@ -44,6 +44,38 @@
#ifdef CONFIG_LIBC_LOCALE
/****************************************************************************
* Private Data
****************************************************************************/
static struct lconv g_c_lconv =
{
.decimal_point = ".",
.thousands_sep = "",
.grouping = "",
.int_curr_symbol = "",
.currency_symbol = "",
.mon_decimal_point = "",
.mon_thousands_sep = "",
.mon_grouping = "",
.positive_sign = "",
.negative_sign = "",
.int_frac_digits = CHAR_MAX,
.frac_digits = CHAR_MAX,
.p_cs_precedes = CHAR_MAX,
.p_sep_by_space = CHAR_MAX,
.n_cs_precedes = CHAR_MAX,
.n_sep_by_space = CHAR_MAX,
.p_sign_posn = CHAR_MAX,
.n_sign_posn = CHAR_MAX,
.int_p_cs_precedes = CHAR_MAX,
.int_p_sep_by_space = CHAR_MAX,
.int_n_cs_precedes = CHAR_MAX,
.int_n_sep_by_space = CHAR_MAX,
.int_p_sign_posn = CHAR_MAX,
.int_n_sign_posn = CHAR_MAX,
};
/****************************************************************************
* Public Functions
****************************************************************************/
@ -62,8 +94,6 @@
FAR struct lconv *localeconv(void)
{
/* NULL indicates the locale was not changed */
return NULL;
return &g_c_lconv;
}
#endif

View File

@ -63,12 +63,7 @@
FAR char *setlocale(int category, FAR const char *locale)
{
if (locale == NULL)
{
return NULL;
}
return ((strcmp(locale, "POSIX") == 0 || strcmp(locale, "C") == 0 ||
strcmp(locale, "") == 0) ? "C" : NULL);
return ((locale == NULL || strcmp(locale, "POSIX") == 0 ||
strcmp(locale, "C") == 0 || strcmp(locale, "") == 0) ? "C" : NULL);
}
#endif