/*
* Category names for getenv()
*/
-static char *categories[_LC_LAST] = {
+static const char * const categories[_LC_LAST] = {
"LC_ALL",
"LC_COLLATE",
"LC_CTYPE",
static char new_categories[_LC_LAST][ENCODING_LEN + 1];
static char saved_categories[_LC_LAST][ENCODING_LEN + 1];
-static char current_locale_string[_LC_LAST * (ENCODING_LEN + 1/*"/"*/ + 1)];
-
static char *currentlocale(void);
static char *loadlocale(int);
__private_extern__ const char *__get_locale_env(int);
{
int i;
- (void)strcpy(current_locale_string, current_categories[1]);
+ size_t bufsiz = _LC_LAST * (ENCODING_LEN + 1/*"/"*/ + 1);
+ static char *current_locale_string = NULL;
+
+ if (current_locale_string == NULL) {
+ current_locale_string = malloc(bufsiz);
+ if (current_locale_string == NULL) {
+ return NULL;
+ }
+ }
+
+ (void)strlcpy(current_locale_string, current_categories[1], bufsiz);
for (i = 2; i < _LC_LAST; ++i)
if (strcmp(current_categories[1], current_categories[i])) {