]> git.saurik.com Git - apple/libc.git/blame_incremental - locale/FreeBSD/setlocale.c.patch
Libc-594.9.5.tar.gz
[apple/libc.git] / locale / FreeBSD / setlocale.c.patch
... / ...
CommitLineData
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
4 #include <sys/cdefs.h>
5 __FBSDID("$FreeBSD: src/lib/libc/locale/setlocale.c,v 1.50 2004/01/31 19:15:32 ache Exp $");
6
7+#include "xlocale_private.h"
8+
9 #include <sys/types.h>
10 #include <sys/stat.h>
11 #include <errno.h>
12@@ -56,7 +58,7 @@ __FBSDID("$FreeBSD: src/lib/libc/locale/
13 #include "lmessages.h" /* for __messages_load_locale() */
14 #include "setlocale.h"
15 #include "ldpart.h"
16-#include "../stdtime/timelocal.h" /* for __time_load_locale() */
17+#include "timelocal.h" /* for __time_load_locale() */
18
19 /*
20 * Category names for getenv()
21@@ -99,15 +101,18 @@ static char current_locale_string[_LC_LA
22
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);
27+
28+#define UNLOCK_AND_RETURN(x) {XL_UNLOCK(&__global_locale); return (x);}
29
30 char *
31 setlocale(category, locale)
32 int category;
33 const char *locale;
34 {
35- int i, j, len, saverr;
36+ int i, j, len, saverr, save__numeric_fp_cvt;
37 const char *env, *r;
38+ locale_t save__lc_numeric_loc;
39
40 if (category < LC_ALL || category >= _LC_LAST) {
41 errno = EINVAL;
42@@ -118,6 +123,7 @@ setlocale(category, locale)
43 return (category != LC_ALL ?
44 current_categories[category] : currentlocale());
45
46+ XL_LOCK(&__global_locale);
47 /*
48 * Default to the current locale for everything.
49 */
50@@ -133,7 +139,7 @@ setlocale(category, locale)
51 env = __get_locale_env(i);
52 if (strlen(env) > ENCODING_LEN) {
53 errno = EINVAL;
54- return (NULL);
55+ UNLOCK_AND_RETURN (NULL);
56 }
57 (void)strcpy(new_categories[i], env);
58 }
59@@ -141,21 +147,21 @@ setlocale(category, locale)
60 env = __get_locale_env(category);
61 if (strlen(env) > ENCODING_LEN) {
62 errno = EINVAL;
63- return (NULL);
64+ UNLOCK_AND_RETURN (NULL);
65 }
66 (void)strcpy(new_categories[category], env);
67 }
68 } else if (category != LC_ALL) {
69 if (strlen(locale) > ENCODING_LEN) {
70 errno = EINVAL;
71- return (NULL);
72+ UNLOCK_AND_RETURN (NULL);
73 }
74 (void)strcpy(new_categories[category], locale);
75 } else {
76 if ((r = strchr(locale, '/')) == NULL) {
77 if (strlen(locale) > ENCODING_LEN) {
78 errno = EINVAL;
79- return (NULL);
80+ UNLOCK_AND_RETURN (NULL);
81 }
82 for (i = 1; i < _LC_LAST; ++i)
83 (void)strcpy(new_categories[i], locale);
84@@ -164,14 +170,14 @@ setlocale(category, locale)
85 ;
86 if (!r[1]) {
87 errno = EINVAL;
88- return (NULL); /* Hmm, just slashes... */
89+ UNLOCK_AND_RETURN (NULL); /* Hmm, just slashes... */
90 }
91 do {
92 if (i == _LC_LAST)
93 break; /* Too many slashes... */
94 if ((len = r - locale) > ENCODING_LEN) {
95 errno = EINVAL;
96- return (NULL);
97+ UNLOCK_AND_RETURN (NULL);
98 }
99 (void)strlcpy(new_categories[i], locale,
100 len + 1);
101@@ -191,8 +197,11 @@ setlocale(category, locale)
102 }
103
104 if (category != LC_ALL)
105- return (loadlocale(category));
106+ UNLOCK_AND_RETURN (loadlocale(category));
107
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)
115 (void)loadlocale(j);
116 }
117 }
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);
121 errno = saverr;
122- return (NULL);
123+ UNLOCK_AND_RETURN (NULL);
124 }
125 }
126- return (currentlocale());
127+ XL_RELEASE(save__lc_numeric_loc);
128+ UNLOCK_AND_RETURN (currentlocale());
129 }
130
131 static char *
132@@ -237,7 +250,7 @@ loadlocale(category)
133 {
134 char *new = new_categories[category];
135 char *old = current_categories[category];
136- int (*func)(const char *);
137+ int (*func)(const char *, locale_t);
138 int saved_errno;
139
140 if ((new[0] == '.' &&
141@@ -280,15 +293,26 @@ loadlocale(category)
142 if (strcmp(new, old) == 0)
143 return (old);
144
145- if (func(new) != _LDP_ERROR) {
146+ if (func(new, &__global_locale) != _LDP_ERROR) {
147 (void)strcpy(old, new);
148+ switch (category) {
149+ case LC_CTYPE:
150+ if (__global_locale.__numeric_fp_cvt == LC_NUMERIC_FP_SAME_LOCALE)
151+ __global_locale.__numeric_fp_cvt = LC_NUMERIC_FP_UNINITIALIZED;
152+ break;
153+ case LC_NUMERIC:
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;
157+ break;
158+ }
159 return (old);
160 }
161
162 return (NULL);
163 }
164
165-static const char *
166+__private_extern__ const char *
167 __get_locale_env(category)
168 int category;
169 {
170@@ -315,7 +339,7 @@ __get_locale_env(category)
171 /*
172 * Detect locale storage location and store its value to _PathLocale variable
173 */
174-int
175+__private_extern__ int
176 __detect_path_locale(void)
177 {
178 if (_PathLocale == NULL) {