]> git.saurik.com Git - apple/libc.git/blame - locale/FreeBSD/localeconv.c.patch
Libc-594.9.5.tar.gz
[apple/libc.git] / locale / FreeBSD / localeconv.c.patch
CommitLineData
34e8f829
A
1--- localeconv.c.orig 2008-10-09 11:37:42.000000000 -0700
2+++ localeconv.c 2008-10-10 01:37:33.000000000 -0700
b5d655f7 3@@ -38,11 +38,71 @@ static char sccsid[] = "@(#)localeconv.c
9385eb3d 4 #include <sys/cdefs.h>
3d9156a7 5 __FBSDID("$FreeBSD: src/lib/libc/locale/localeconv.c,v 1.13 2003/06/26 10:46:16 phantom Exp $");
9385eb3d 6
3d9156a7
A
7+#include "xlocale_private.h"
8+
9385eb3d
A
9+#include <limits.h>
10 #include <locale.h>
3d9156a7 11
9385eb3d
A
12 #include "lmonetary.h"
13 #include "lnumeric.h"
14
b5d655f7 15+#ifdef __APPLE_PR3417676_HACK__
9385eb3d
A
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+}
b5d655f7 70+#endif /* __APPLE_PR3417676_HACK__ */
9385eb3d
A
71+
72 /*
73 * The localeconv() function constructs a struct lconv from the current
74 * monetary and numeric locales.
34e8f829 75@@ -52,25 +112,28 @@ __FBSDID("$FreeBSD: src/lib/libc/locale/
3d9156a7
A
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)
9385eb3d 88 {
3d9156a7 89- static struct lconv ret;
34e8f829 90+ struct lconv *lc;
3d9156a7
A
91+
92+ NORMALIZE_LOCALE(loc);
3d9156a7
A
93
94- if (__mlocale_changed) {
95+ if (loc->__mlocale_changed) {
34e8f829
A
96+ XL_LOCK(loc);
97+ if (loc->__mlocale_changed) {
3d9156a7
A
98 /* LC_MONETARY part */
99 struct lc_monetary_T * mptr;
34e8f829 100+ struct lconv *lc = &loc->__lc_localeconv;
3d9156a7
A
101
102-#define M_ASSIGN_STR(NAME) (ret.NAME = (char*)mptr->NAME)
103-#define M_ASSIGN_CHAR(NAME) (ret.NAME = mptr->NAME[0])
34e8f829
A
104+#define M_ASSIGN_STR(NAME) (lc->NAME = (char*)mptr->NAME)
105+#define M_ASSIGN_CHAR(NAME) (lc->NAME = mptr->NAME[0])
3d9156a7
A
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);
34e8f829 112@@ -92,21 +155,45 @@ localeconv()
3d9156a7
A
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;
34e8f829
A
118+ }
119+ XL_UNLOCK(loc);
3d9156a7
A
120 }
121
122- if (__nlocale_changed) {
123+ if (loc->__nlocale_changed) {
34e8f829
A
124+ XL_LOCK(loc);
125+ if (loc->__nlocale_changed) {
3d9156a7
A
126 /* LC_NUMERIC part */
127 struct lc_numeric_T * nptr;
34e8f829 128+ struct lconv *lc = &loc->__lc_localeconv;
3d9156a7
A
129
130-#define N_ASSIGN_STR(NAME) (ret.NAME = (char*)nptr->NAME)
34e8f829 131+#define N_ASSIGN_STR(NAME) (lc->NAME = (char*)nptr->NAME)
3d9156a7
A
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;
34e8f829
A
140+ }
141+ XL_UNLOCK(loc);
3d9156a7
A
142 }
143
144- return (&ret);
34e8f829 145+ return &loc->__lc_localeconv;
3d9156a7 146+}
9385eb3d 147+
3d9156a7
A
148+/*
149+ * Return the current locale conversion.
150+ */
151+struct lconv *
152+localeconv()
153+{
b5d655f7 154+#ifdef __APPLE_PR3417676_HACK__
9385eb3d
A
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;
b5d655f7 161+#endif /* __APPLE_PR3417676_HACK__ */
3d9156a7
A
162+ return localeconv_l(__current_locale());
163 }