]> git.saurik.com Git - apple/libc.git/blame_incremental - locale/FreeBSD/localeconv.c.patch
Libc-763.13.tar.gz
[apple/libc.git] / locale / FreeBSD / localeconv.c.patch
... / ...
CommitLineData
1--- localeconv.c.orig 2009-11-09 15:05:25.000000000 -0800
2+++ localeconv.c 2009-11-09 15:05:26.000000000 -0800
3@@ -34,11 +34,71 @@ static char sccsid[] = "@(#)localeconv.c
4 #include <sys/cdefs.h>
5 __FBSDID("$FreeBSD: src/lib/libc/locale/localeconv.c,v 1.14 2007/12/12 07:43:23 phantom Exp $");
6
7+#include "xlocale_private.h"
8+
9+#include <limits.h>
10 #include <locale.h>
11
12 #include "lmonetary.h"
13 #include "lnumeric.h"
14
15+#ifdef __APPLE_PR3417676_HACK__
16+/*------------------------------------------------------------------------
17+ * PR-3417676: We need to provide a way to force "C" locale style number
18+ * formatting independent of the locale setting. We provide private
19+ * routines to get and set a flag that tells localeconv() to either return
20+ * a "C" struct lconv, or the one dependent on the actual locale.
21+ *------------------------------------------------------------------------*/
22+static char empty[] = "";
23+static char numempty[] = { CHAR_MAX, '\0' };
24+
25+/*
26+ * Default (C) locale conversion.
27+ */
28+static struct lconv _C_lconv = {
29+ ".", /* decimal_point */
30+ empty, /* thousands_sep */
31+ numempty, /* grouping */
32+ empty, /* int_curr_symbol */
33+ empty, /* currency_symbol */
34+ empty, /* mon_decimal_point */
35+ empty, /* mon_thousands_sep */
36+ numempty, /* mon_grouping */
37+ empty, /* positive_sign */
38+ empty, /* negative_sign */
39+ CHAR_MAX, /* int_frac_digits */
40+ CHAR_MAX, /* frac_digits */
41+ CHAR_MAX, /* p_cs_precedes */
42+ CHAR_MAX, /* p_sep_by_space */
43+ CHAR_MAX, /* n_cs_precedes */
44+ CHAR_MAX, /* n_sep_by_space */
45+ CHAR_MAX, /* p_sign_posn */
46+ CHAR_MAX, /* n_sign_posn */
47+ CHAR_MAX, /* int_p_cs_precedes */
48+ CHAR_MAX, /* int_n_cs_precedes */
49+ CHAR_MAX, /* int_p_sep_by_space */
50+ CHAR_MAX, /* int_n_sep_by_space */
51+ CHAR_MAX, /* int_p_sign_posn */
52+ CHAR_MAX, /* int_n_sign_posn */
53+};
54+static int _onlyClocaleconv = 0;
55+
56+int
57+__getonlyClocaleconv(void)
58+{
59+ return _onlyClocaleconv;
60+}
61+
62+int
63+__setonlyClocaleconv(int val)
64+{
65+ int prev = _onlyClocaleconv;
66+
67+ _onlyClocaleconv = val;
68+ return prev;
69+}
70+#endif /* __APPLE_PR3417676_HACK__ */
71+
72 /*
73 * The localeconv() function constructs a struct lconv from the current
74 * monetary and numeric locales.
75@@ -48,25 +108,28 @@ __FBSDID("$FreeBSD: src/lib/libc/locale/
76 * lconv structure are computed only when the monetary or numeric
77 * locale has been changed.
78 */
79-int __mlocale_changed = 1;
80-int __nlocale_changed = 1;
81
82 /*
83 * Return the current locale conversion.
84 */
85 struct lconv *
86-localeconv()
87+localeconv_l(locale_t loc)
88 {
89- static struct lconv ret;
90+ struct lconv *lc;
91+
92+ NORMALIZE_LOCALE(loc);
93
94- if (__mlocale_changed) {
95+ if (loc->__mlocale_changed) {
96+ XL_LOCK(loc);
97+ if (loc->__mlocale_changed) {
98 /* LC_MONETARY part */
99 struct lc_monetary_T * mptr;
100+ struct lconv *lc = &loc->__lc_localeconv;
101
102-#define M_ASSIGN_STR(NAME) (ret.NAME = (char*)mptr->NAME)
103-#define M_ASSIGN_CHAR(NAME) (ret.NAME = mptr->NAME[0])
104+#define M_ASSIGN_STR(NAME) (lc->NAME = (char*)mptr->NAME)
105+#define M_ASSIGN_CHAR(NAME) (lc->NAME = mptr->NAME[0])
106
107- mptr = __get_current_monetary_locale();
108+ mptr = __get_current_monetary_locale(loc);
109 M_ASSIGN_STR(int_curr_symbol);
110 M_ASSIGN_STR(currency_symbol);
111 M_ASSIGN_STR(mon_decimal_point);
112@@ -88,21 +151,45 @@ localeconv()
113 M_ASSIGN_CHAR(int_n_sep_by_space);
114 M_ASSIGN_CHAR(int_p_sign_posn);
115 M_ASSIGN_CHAR(int_n_sign_posn);
116- __mlocale_changed = 0;
117+ loc->__mlocale_changed = 0;
118+ }
119+ XL_UNLOCK(loc);
120 }
121
122- if (__nlocale_changed) {
123+ if (loc->__nlocale_changed) {
124+ XL_LOCK(loc);
125+ if (loc->__nlocale_changed) {
126 /* LC_NUMERIC part */
127 struct lc_numeric_T * nptr;
128+ struct lconv *lc = &loc->__lc_localeconv;
129
130-#define N_ASSIGN_STR(NAME) (ret.NAME = (char*)nptr->NAME)
131+#define N_ASSIGN_STR(NAME) (lc->NAME = (char*)nptr->NAME)
132
133- nptr = __get_current_numeric_locale();
134+ nptr = __get_current_numeric_locale(loc);
135 N_ASSIGN_STR(decimal_point);
136 N_ASSIGN_STR(thousands_sep);
137 N_ASSIGN_STR(grouping);
138- __nlocale_changed = 0;
139+ loc->__nlocale_changed = 0;
140+ }
141+ XL_UNLOCK(loc);
142 }
143
144- return (&ret);
145+ return &loc->__lc_localeconv;
146+}
147+
148+/*
149+ * Return the current locale conversion.
150+ */
151+struct lconv *
152+localeconv()
153+{
154+#ifdef __APPLE_PR3417676_HACK__
155+ /*--------------------------------------------------------------------
156+ * If _onlyClocaleconv is non-zero, just return __lconv, which is a "C"
157+ * struct lconv *. Otherwise, do the normal thing.
158+ *--------------------------------------------------------------------*/
159+ if (_onlyClocaleconv)
160+ return &_C_lconv;
161+#endif /* __APPLE_PR3417676_HACK__ */
162+ return localeconv_l(__current_locale());
163 }