Change the loadlocale() prototype to be callable with specified locale_t
parameter. It will permit to reuse the code path for uselocale(3).
The current usage (with setlocale(3)) will just pass the global locale
state to function call.
--
Sebastien Marie
Index: b/lib/libc/locale/setlocale.c
===================================================================
--- a/lib/libc/locale/setlocale.c 2015-07-12 16:00:44.917433274 +0200
+++ b/lib/libc/locale/setlocale.c 2015-07-12 16:18:55.314603522 +0200
@@ -60,9 +60,9 @@
static char current_locale_string[_LC_LAST * 33];
static char *currentlocale(void);
-static void revert_to_default(int);
-static int load_locale_sub(int, const char *);
-static char *loadlocale(int, const char *);
+static void revert_to_default(int, struct _locale_t *);
+static int load_locale_sub(int, const char *, struct _locale_t *);
+static char *loadlocale(int, const char *, struct _locale_t *);
static const char *__get_locale_env(int);
char *
@@ -140,11 +140,13 @@
}
if (category)
- return (loadlocale(category, new_categories[category]));
+ return (loadlocale(category, new_categories[category],
+ &_lc_global_locale));
loadlocale_success = 0;
for (i = 1; i < _LC_LAST; ++i) {
- if (loadlocale(i, new_categories[i]) != NULL)
+ if (loadlocale(i, new_categories[i],
+ &_lc_global_locale) != NULL)
loadlocale_success = 1;
}
@@ -184,11 +186,11 @@
}
static void
-revert_to_default(int category)
+revert_to_default(int category, struct _locale_t *locale)
{
switch (category) {
case LC_CTYPE:
- (void)_xpg4_setrunelocale("C", LC_GLOBAL_LOCALE);
+ (void)_xpg4_setrunelocale("C", locale);
break;
case LC_MESSAGES:
case LC_COLLATE:
@@ -229,11 +231,11 @@
}
static int
-load_locale_sub(int category, const char *locname)
+load_locale_sub(int category, const char *locname, struct _locale_t *locale)
{
/* check for the default locales */
if (!strcmp(locname, "C") || !strcmp(locname, "POSIX")) {
- revert_to_default(category);
+ revert_to_default(category, locale);
return 0;
}
@@ -243,7 +245,7 @@
switch (category) {
case LC_CTYPE:
- if (_xpg4_setrunelocale(locname, LC_GLOBAL_LOCALE))
+ if (_xpg4_setrunelocale(locname, locale))
return -1;
break;
@@ -261,16 +263,16 @@
}
static char *
-loadlocale(int category, const char *locname)
+loadlocale(int category, const char *locname, struct _locale_t *locale)
{
- if (strcmp(locname, _lc_global_locale.categories[category]) == 0)
- return (_lc_global_locale.categories[category]);
+ if (strcmp(locname, locale->categories[category]) == 0)
+ return (locale->categories[category]);
- if (!load_locale_sub(category, locname)) {
- (void)strlcpy(_lc_global_locale.categories[category],
+ if (!load_locale_sub(category, locname, locale)) {
+ (void)strlcpy(locale->categories[category],
locname,
- sizeof(_lc_global_locale.categories[category]));
- return _lc_global_locale.categories[category];
+ sizeof(locale->categories[category]));
+ return locale->categories[category];
} else {
return NULL;
}