+ int category;
+ const char *locale;
+ {
+- int i, j, len, saverr;
++ int i, j, len, saverr, save__numeric_fp_cvt;
+ const char *env, *r;
++ locale_t save__lc_numeric_loc;
+
+ if (category < LC_ALL || category >= _LC_LAST) {
+ errno = EINVAL;
+@@ -114,6 +119,7 @@ setlocale(category, locale)
+ return (category != LC_ALL ?
+ current_categories[category] : currentlocale());
+
++ XL_LOCK(&__global_locale);
+ /*
+ * Default to the current locale for everything.
+ */
+@@ -129,7 +135,7 @@ setlocale(category, locale)
+ env = __get_locale_env(i);
+ if (strlen(env) > ENCODING_LEN) {
+ errno = EINVAL;
+- return (NULL);
++ UNLOCK_AND_RETURN (NULL);
+ }
+ (void)strcpy(new_categories[i], env);
+ }
+@@ -137,21 +143,21 @@ setlocale(category, locale)
+ env = __get_locale_env(category);
+ if (strlen(env) > ENCODING_LEN) {
+ errno = EINVAL;
+- return (NULL);
++ UNLOCK_AND_RETURN (NULL);
+ }
+ (void)strcpy(new_categories[category], env);
+ }
+ } else if (category != LC_ALL) {
+ if (strlen(locale) > ENCODING_LEN) {
+ errno = EINVAL;
+- return (NULL);
++ UNLOCK_AND_RETURN (NULL);
+ }
+ (void)strcpy(new_categories[category], locale);
+ } else {
+ if ((r = strchr(locale, '/')) == NULL) {
+ if (strlen(locale) > ENCODING_LEN) {
+ errno = EINVAL;
+- return (NULL);
++ UNLOCK_AND_RETURN (NULL);
+ }
+ for (i = 1; i < _LC_LAST; ++i)
+ (void)strcpy(new_categories[i], locale);
+@@ -160,14 +166,14 @@ setlocale(category, locale)
+ ;
+ if (!r[1]) {
+ errno = EINVAL;
+- return (NULL); /* Hmm, just slashes... */
++ UNLOCK_AND_RETURN (NULL); /* Hmm, just slashes... */
+ }
+ do {
+ if (i == _LC_LAST)
+ break; /* Too many slashes... */
+ if ((len = r - locale) > ENCODING_LEN) {
+ errno = EINVAL;
+- return (NULL);
++ UNLOCK_AND_RETURN (NULL);
+ }
+ (void)strlcpy(new_categories[i], locale,
+ len + 1);
+@@ -187,8 +193,11 @@ setlocale(category, locale)
+ }
+
+ if (category != LC_ALL)
+- return (loadlocale(category));
++ UNLOCK_AND_RETURN (loadlocale(category));
+
++ save__numeric_fp_cvt = __global_locale.__numeric_fp_cvt;
++ save__lc_numeric_loc = __global_locale.__lc_numeric_loc;
++ XL_RETAIN(save__lc_numeric_loc);
+ for (i = 1; i < _LC_LAST; ++i) {
+ (void)strcpy(saved_categories[i], current_categories[i]);
+ if (loadlocale(i) == NULL) {
+@@ -201,11 +210,15 @@ setlocale(category, locale)
+ (void)loadlocale(j);
+ }
+ }
++ __global_locale.__numeric_fp_cvt = save__numeric_fp_cvt;
++ __global_locale.__lc_numeric_loc = save__lc_numeric_loc;
++ XL_RELEASE(save__lc_numeric_loc);
+ errno = saverr;
+- return (NULL);
++ UNLOCK_AND_RETURN (NULL);
+ }
+ }
+- return (currentlocale());
++ XL_RELEASE(save__lc_numeric_loc);
++ UNLOCK_AND_RETURN (currentlocale());
+ }
+
+ static char *
+@@ -233,7 +246,7 @@ loadlocale(category)