]>
Commit | Line | Data |
---|---|---|
b5d655f7 A |
1 | --- localeconv.c.orig 2008-03-15 10:50:38.000000000 -0700 |
2 | +++ localeconv.c 2008-03-26 16:49:24.000000000 -0700 | |
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. | |
b5d655f7 | 75 | @@ -52,25 +112,37 @@ __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 A |
89 | - static struct lconv ret; |
90 | + struct __xlocale_st_localeconv *lc; | |
91 | + | |
92 | + NORMALIZE_LOCALE(loc); | |
93 | + if (loc->__lc_localeconv && !loc->__mlocale_changed && !loc->__nlocale_changed) | |
94 | + return &loc->__lc_localeconv->__ret; | |
95 | + | |
96 | + lc = (struct __xlocale_st_localeconv *)malloc(sizeof(struct __xlocale_st_localeconv)); | |
97 | + lc->__refcount = 1; | |
98 | + lc->__free_extra = NULL; | |
99 | + if (loc->__lc_localeconv) | |
100 | + lc->__ret = loc->__lc_localeconv->__ret; | |
101 | + else { | |
102 | + loc->__mlocale_changed = 1; | |
103 | + loc->__nlocale_changed = 1; | |
104 | + } | |
105 | ||
106 | - if (__mlocale_changed) { | |
107 | + if (loc->__mlocale_changed) { | |
108 | /* LC_MONETARY part */ | |
109 | struct lc_monetary_T * mptr; | |
110 | ||
111 | -#define M_ASSIGN_STR(NAME) (ret.NAME = (char*)mptr->NAME) | |
112 | -#define M_ASSIGN_CHAR(NAME) (ret.NAME = mptr->NAME[0]) | |
113 | +#define M_ASSIGN_STR(NAME) (lc->__ret.NAME = (char*)mptr->NAME) | |
114 | +#define M_ASSIGN_CHAR(NAME) (lc->__ret.NAME = mptr->NAME[0]) | |
115 | ||
116 | - mptr = __get_current_monetary_locale(); | |
117 | + mptr = __get_current_monetary_locale(loc); | |
118 | M_ASSIGN_STR(int_curr_symbol); | |
119 | M_ASSIGN_STR(currency_symbol); | |
120 | M_ASSIGN_STR(mon_decimal_point); | |
b5d655f7 | 121 | @@ -92,21 +164,41 @@ localeconv() |
3d9156a7 A |
122 | M_ASSIGN_CHAR(int_n_sep_by_space); |
123 | M_ASSIGN_CHAR(int_p_sign_posn); | |
124 | M_ASSIGN_CHAR(int_n_sign_posn); | |
125 | - __mlocale_changed = 0; | |
126 | + loc->__mlocale_changed = 0; | |
127 | } | |
128 | ||
129 | - if (__nlocale_changed) { | |
130 | + if (loc->__nlocale_changed) { | |
131 | /* LC_NUMERIC part */ | |
132 | struct lc_numeric_T * nptr; | |
133 | ||
134 | -#define N_ASSIGN_STR(NAME) (ret.NAME = (char*)nptr->NAME) | |
135 | +#define N_ASSIGN_STR(NAME) (lc->__ret.NAME = (char*)nptr->NAME) | |
136 | ||
137 | - nptr = __get_current_numeric_locale(); | |
138 | + nptr = __get_current_numeric_locale(loc); | |
139 | N_ASSIGN_STR(decimal_point); | |
140 | N_ASSIGN_STR(thousands_sep); | |
141 | N_ASSIGN_STR(grouping); | |
142 | - __nlocale_changed = 0; | |
143 | + loc->__nlocale_changed = 0; | |
144 | } | |
145 | ||
146 | - return (&ret); | |
147 | + XL_RELEASE(loc->__lc_localeconv); | |
148 | + loc->__lc_localeconv = lc; | |
149 | + | |
150 | + return (&lc->__ret); | |
151 | +} | |
9385eb3d | 152 | + |
3d9156a7 A |
153 | +/* |
154 | + * Return the current locale conversion. | |
155 | + */ | |
156 | +struct lconv * | |
157 | +localeconv() | |
158 | +{ | |
b5d655f7 | 159 | +#ifdef __APPLE_PR3417676_HACK__ |
9385eb3d A |
160 | + /*-------------------------------------------------------------------- |
161 | + * If _onlyClocaleconv is non-zero, just return __lconv, which is a "C" | |
162 | + * struct lconv *. Otherwise, do the normal thing. | |
163 | + *--------------------------------------------------------------------*/ | |
164 | + if (_onlyClocaleconv) | |
165 | + return &_C_lconv; | |
b5d655f7 | 166 | +#endif /* __APPLE_PR3417676_HACK__ */ |
3d9156a7 A |
167 | + return localeconv_l(__current_locale()); |
168 | } |