X-Git-Url: https://git.saurik.com/apple/libc.git/blobdiff_plain/ad3c9f2af814c84582fdd1649e49ec4f68572c5a..15de9d6b4ab2de27ae24b13b7b6c4d55fffe4aef:/locale/FreeBSD/setlocale.c diff --git a/locale/FreeBSD/setlocale.c b/locale/FreeBSD/setlocale.c index 9729e54..c65d189 100644 --- a/locale/FreeBSD/setlocale.c +++ b/locale/FreeBSD/setlocale.c @@ -59,7 +59,7 @@ __FBSDID("$FreeBSD: src/lib/libc/locale/setlocale.c,v 1.51 2007/01/09 00:28:00 i /* * Category names for getenv() */ -static char *categories[_LC_LAST] = { +static const char * const categories[_LC_LAST] = { "LC_ALL", "LC_COLLATE", "LC_CTYPE", @@ -93,8 +93,6 @@ char *_PathLocale; 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); @@ -226,7 +224,17 @@ currentlocale() { 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])) {