summaryrefslogtreecommitdiff
path: root/lib/libc/locale
diff options
context:
space:
mode:
authorsemarie <semarie@cvs.openbsd.org>2015-07-02 16:07:44 +0000
committersemarie <semarie@cvs.openbsd.org>2015-07-02 16:07:44 +0000
commite3fa8cd9f440441f5f9e23fcc742e8b78ffb3136 (patch)
tree9cc5f1ac881f0a5ea9a2f4c6e3dc3b1bfb631a1b /lib/libc/locale
parentc721369001e8145f2de588732047630d0f56f98d (diff)
remove new_categories variable from global.
This variable is used as temporary buffer in order to do checking before copying the content to current_categories variable. Switch it as local variable in setlocale function. Adapts some functions. the commit collapse 3 proposed diffs on tech@, and all OK stsp@
Diffstat (limited to 'lib/libc/locale')
-rw-r--r--lib/libc/locale/setlocale.c26
1 files changed, 10 insertions, 16 deletions
diff --git a/lib/libc/locale/setlocale.c b/lib/libc/locale/setlocale.c
index 06ca9ac345d..ca0594671c5 100644
--- a/lib/libc/locale/setlocale.c
+++ b/lib/libc/locale/setlocale.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: setlocale.c,v 1.21 2015/06/09 20:04:04 stsp Exp $ */
+/* $OpenBSD: setlocale.c,v 1.22 2015/07/02 16:07:43 semarie Exp $ */
/*
* Copyright (c) 1991, 1993
* The Regents of the University of California. All rights reserved.
@@ -68,17 +68,12 @@ static char current_categories[_LC_LAST][32] = {
"C"
};
-/*
- * The locales we are going to try and load
- */
-static char new_categories[_LC_LAST][32];
-
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);
+static char *loadlocale(int, const char *);
static const char *__get_locale_env(int);
char *
@@ -87,6 +82,7 @@ setlocale(int category, const char *locale)
int i, loadlocale_success;
size_t len;
const char *env, *r;
+ char new_categories[_LC_LAST][32];
if (category < 0 || category >= _LC_LAST)
return (NULL);
@@ -153,11 +149,11 @@ setlocale(int category, const char *locale)
}
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;
}
@@ -241,8 +237,7 @@ static int
load_locale_sub(int category, const char *locname)
{
/* check for the default locales */
- if (!strcmp(new_categories[category], "C") ||
- !strcmp(new_categories[category], "POSIX")) {
+ if (!strcmp(locname, "C") || !strcmp(locname, "POSIX")) {
revert_to_default(category);
return 0;
}
@@ -272,15 +267,14 @@ load_locale_sub(int category, const char *locname)
}
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;