Here a second patch which remove the use of new_categories from
loadlocale() function.
loadlocate() use only one element from new_categories: the current
category we want to assign to current_categories[category].
So instead of using new_categories globally, we can pass as argument the
locale name (locname), and used it in loadlocate() body for:
- check if the wanted value is already set
- effectively load the locale (load_locale_sub call)
- effectively assign the value in current_categories
--
Sébastien Marie
Index: locale/setlocale.c
===================================================================
RCS file: /cvs/src/lib/libc/locale/setlocale.c,v
retrieving revision 1.21
diff -u -p -r1.21 setlocale.c
--- locale/setlocale.c 9 Jun 2015 20:04:04 -0000 1.21
+++ locale/setlocale.c 12 Jun 2015 13:46:40 -0000
@@ -78,7 +78,7 @@ static char current_locale_string[_LC_LA
static char *currentlocale(void);
static void revert_to_default(int);
static int load_locale_sub(int, const char *);
-static char *loadlocale(int);
+static char *loadlocale(int, const char *);
static const char *__get_locale_env(int);
char *
@@ -153,11 +153,11 @@ setlocale(int category, const char *loca
}
if (category)
- return (loadlocale(category));
+ return (loadlocale(category, new_categories[category]));
loadlocale_success = 0;
for (i = 1; i < _LC_LAST; ++i) {
- if (loadlocale(i) != NULL)
+ if (loadlocale(i, new_categories[i]) != NULL)
loadlocale_success = 1;
}
@@ -272,15 +271,14 @@ load_locale_sub(int category, const char
}
static char *
-loadlocale(int category)
+loadlocale(int category, const char *locname)
{
- if (strcmp(new_categories[category],
- current_categories[category]) == 0)
+ if (strcmp(locname, current_categories[category]) == 0)
return (current_categories[category]);
- if (!load_locale_sub(category, new_categories[category])) {
+ if (!load_locale_sub(category, locname)) {
(void)strlcpy(current_categories[category],
- new_categories[category],
sizeof(current_categories[category]));
+ locname, sizeof(current_categories[category]));
return current_categories[category];
} else {
return NULL;