1 --- setlocale.c.orig 2008-01-24 17:13:46.000000000 -0800
2 +++ setlocale.c 2008-02-17 13:23:02.000000000 -0800
3 @@ -41,6 +41,8 @@ static char sccsid[] = "@(#)setlocale.c
5 __FBSDID("$FreeBSD: src/lib/libc/locale/setlocale.c,v 1.50 2004/01/31 19:15:32 ache Exp $");
7 +#include "xlocale_private.h"
12 @@ -56,7 +58,7 @@ __FBSDID("$FreeBSD: src/lib/libc/locale/
13 #include "lmessages.h" /* for __messages_load_locale() */
14 #include "setlocale.h"
16 -#include "../stdtime/timelocal.h" /* for __time_load_locale() */
17 +#include "timelocal.h" /* for __time_load_locale() */
20 * Category names for getenv()
21 @@ -99,15 +101,18 @@ static char current_locale_string[_LC_LA
23 static char *currentlocale(void);
24 static char *loadlocale(int);
25 -static const char *__get_locale_env(int);
26 +__private_extern__ const char *__get_locale_env(int);
28 +#define UNLOCK_AND_RETURN(x) {XL_UNLOCK(&__global_locale); return (x);}
31 setlocale(category, locale)
35 - int i, j, len, saverr;
36 + int i, j, len, saverr, save__numeric_fp_cvt;
38 + locale_t save__lc_numeric_loc;
40 if (category < LC_ALL || category >= _LC_LAST) {
42 @@ -118,6 +123,7 @@ setlocale(category, locale)
43 return (category != LC_ALL ?
44 current_categories[category] : currentlocale());
46 + XL_LOCK(&__global_locale);
48 * Default to the current locale for everything.
50 @@ -133,7 +139,7 @@ setlocale(category, locale)
51 env = __get_locale_env(i);
52 if (strlen(env) > ENCODING_LEN) {
55 + UNLOCK_AND_RETURN (NULL);
57 (void)strcpy(new_categories[i], env);
59 @@ -141,21 +147,21 @@ setlocale(category, locale)
60 env = __get_locale_env(category);
61 if (strlen(env) > ENCODING_LEN) {
64 + UNLOCK_AND_RETURN (NULL);
66 (void)strcpy(new_categories[category], env);
68 } else if (category != LC_ALL) {
69 if (strlen(locale) > ENCODING_LEN) {
72 + UNLOCK_AND_RETURN (NULL);
74 (void)strcpy(new_categories[category], locale);
76 if ((r = strchr(locale, '/')) == NULL) {
77 if (strlen(locale) > ENCODING_LEN) {
80 + UNLOCK_AND_RETURN (NULL);
82 for (i = 1; i < _LC_LAST; ++i)
83 (void)strcpy(new_categories[i], locale);
84 @@ -164,14 +170,14 @@ setlocale(category, locale)
88 - return (NULL); /* Hmm, just slashes... */
89 + UNLOCK_AND_RETURN (NULL); /* Hmm, just slashes... */
93 break; /* Too many slashes... */
94 if ((len = r - locale) > ENCODING_LEN) {
97 + UNLOCK_AND_RETURN (NULL);
99 (void)strlcpy(new_categories[i], locale,
101 @@ -191,8 +197,11 @@ setlocale(category, locale)
104 if (category != LC_ALL)
105 - return (loadlocale(category));
106 + UNLOCK_AND_RETURN (loadlocale(category));
108 + save__numeric_fp_cvt = __global_locale.__numeric_fp_cvt;
109 + save__lc_numeric_loc = __global_locale.__lc_numeric_loc;
110 + XL_RETAIN(save__lc_numeric_loc);
111 for (i = 1; i < _LC_LAST; ++i) {
112 (void)strcpy(saved_categories[i], current_categories[i]);
113 if (loadlocale(i) == NULL) {
114 @@ -205,11 +214,15 @@ setlocale(category, locale)
118 + __global_locale.__numeric_fp_cvt = save__numeric_fp_cvt;
119 + __global_locale.__lc_numeric_loc = save__lc_numeric_loc;
120 + XL_RELEASE(save__lc_numeric_loc);
123 + UNLOCK_AND_RETURN (NULL);
126 - return (currentlocale());
127 + XL_RELEASE(save__lc_numeric_loc);
128 + UNLOCK_AND_RETURN (currentlocale());
132 @@ -237,7 +250,7 @@ loadlocale(category)
134 char *new = new_categories[category];
135 char *old = current_categories[category];
136 - int (*func)(const char *);
137 + int (*func)(const char *, locale_t);
140 if ((new[0] == '.' &&
141 @@ -280,15 +293,26 @@ loadlocale(category)
142 if (strcmp(new, old) == 0)
145 - if (func(new) != _LDP_ERROR) {
146 + if (func(new, &__global_locale) != _LDP_ERROR) {
147 (void)strcpy(old, new);
148 + switch (category) {
150 + if (__global_locale.__numeric_fp_cvt == LC_NUMERIC_FP_SAME_LOCALE)
151 + __global_locale.__numeric_fp_cvt = LC_NUMERIC_FP_UNINITIALIZED;
154 + __global_locale.__numeric_fp_cvt = LC_NUMERIC_FP_UNINITIALIZED;
155 + XL_RELEASE(__global_locale.__lc_numeric_loc);
156 + __global_locale.__lc_numeric_loc = NULL;
166 +__private_extern__ const char *
167 __get_locale_env(category)
170 @@ -315,7 +339,7 @@ __get_locale_env(category)
172 * Detect locale storage location and store its value to _PathLocale variable
175 +__private_extern__ int
176 __detect_path_locale(void)
178 if (_PathLocale == NULL) {