1 --- localeconv.c.orig 2008-10-09 11:37:42.000000000 -0700
2 +++ localeconv.c 2008-10-10 01:37:33.000000000 -0700
3 @@ -38,11 +38,71 @@ static char sccsid[] = "@(#)localeconv.c
5 __FBSDID("$FreeBSD: src/lib/libc/locale/localeconv.c,v 1.13 2003/06/26 10:46:16 phantom Exp $");
7 +#include "xlocale_private.h"
12 #include "lmonetary.h"
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' };
26 + * Default (C) locale conversion.
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 */
54 +static int _onlyClocaleconv = 0;
57 +__getonlyClocaleconv(void)
59 + return _onlyClocaleconv;
63 +__setonlyClocaleconv(int val)
65 + int prev = _onlyClocaleconv;
67 + _onlyClocaleconv = val;
70 +#endif /* __APPLE_PR3417676_HACK__ */
73 * The localeconv() function constructs a struct lconv from the current
74 * monetary and numeric locales.
75 @@ -52,25 +112,28 @@ __FBSDID("$FreeBSD: src/lib/libc/locale/
76 * lconv structure are computed only when the monetary or numeric
77 * locale has been changed.
79 -int __mlocale_changed = 1;
80 -int __nlocale_changed = 1;
83 * Return the current locale conversion.
87 +localeconv_l(locale_t loc)
89 - static struct lconv ret;
92 + NORMALIZE_LOCALE(loc);
94 - if (__mlocale_changed) {
95 + if (loc->__mlocale_changed) {
97 + if (loc->__mlocale_changed) {
98 /* LC_MONETARY part */
99 struct lc_monetary_T * mptr;
100 + struct lconv *lc = &loc->__lc_localeconv;
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])
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 @@ -92,21 +155,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;
122 - if (__nlocale_changed) {
123 + if (loc->__nlocale_changed) {
125 + if (loc->__nlocale_changed) {
126 /* LC_NUMERIC part */
127 struct lc_numeric_T * nptr;
128 + struct lconv *lc = &loc->__lc_localeconv;
130 -#define N_ASSIGN_STR(NAME) (ret.NAME = (char*)nptr->NAME)
131 +#define N_ASSIGN_STR(NAME) (lc->NAME = (char*)nptr->NAME)
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;
145 + return &loc->__lc_localeconv;
149 + * Return the current locale conversion.
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)
161 +#endif /* __APPLE_PR3417676_HACK__ */
162 + return localeconv_l(__current_locale());