1 --- localeconv.c.orig 2004-11-25 11:38:18.000000000 -0800
2 +++ localeconv.c 2005-02-17 23:35:43.000000000 -0800
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 +/*------------------------------------------------------------------------
16 + * PR-3417676: We need to provide a way to force "C" locale style number
17 + * formatting independent of the locale setting. We provide private
18 + * routines to get and set a flag that tells localeconv() to either return
19 + * a "C" struct lconv, or the one dependent on the actual locale.
20 + *------------------------------------------------------------------------*/
21 +static char empty[] = "";
22 +static char numempty[] = { CHAR_MAX, '\0' };
25 + * Default (C) locale conversion.
27 +static struct lconv _C_lconv = {
28 + ".", /* decimal_point */
29 + empty, /* thousands_sep */
30 + numempty, /* grouping */
31 + empty, /* int_curr_symbol */
32 + empty, /* currency_symbol */
33 + empty, /* mon_decimal_point */
34 + empty, /* mon_thousands_sep */
35 + numempty, /* mon_grouping */
36 + empty, /* positive_sign */
37 + empty, /* negative_sign */
38 + CHAR_MAX, /* int_frac_digits */
39 + CHAR_MAX, /* frac_digits */
40 + CHAR_MAX, /* p_cs_precedes */
41 + CHAR_MAX, /* p_sep_by_space */
42 + CHAR_MAX, /* n_cs_precedes */
43 + CHAR_MAX, /* n_sep_by_space */
44 + CHAR_MAX, /* p_sign_posn */
45 + CHAR_MAX, /* n_sign_posn */
46 + CHAR_MAX, /* int_p_cs_precedes */
47 + CHAR_MAX, /* int_n_cs_precedes */
48 + CHAR_MAX, /* int_p_sep_by_space */
49 + CHAR_MAX, /* int_n_sep_by_space */
50 + CHAR_MAX, /* int_p_sign_posn */
51 + CHAR_MAX, /* int_n_sign_posn */
53 +static int _onlyClocaleconv = 0;
56 +__getonlyClocaleconv(void)
58 + return _onlyClocaleconv;
62 +__setonlyClocaleconv(int val)
64 + int prev = _onlyClocaleconv;
66 + _onlyClocaleconv = val;
71 * The localeconv() function constructs a struct lconv from the current
72 * monetary and numeric locales.
74 * lconv structure are computed only when the monetary or numeric
75 * locale has been changed.
77 -int __mlocale_changed = 1;
78 -int __nlocale_changed = 1;
81 * Return the current locale conversion.
85 +localeconv_l(locale_t loc)
87 - static struct lconv ret;
88 + struct __xlocale_st_localeconv *lc;
90 + NORMALIZE_LOCALE(loc);
91 + if (loc->__lc_localeconv && !loc->__mlocale_changed && !loc->__nlocale_changed)
92 + return &loc->__lc_localeconv->__ret;
94 + lc = (struct __xlocale_st_localeconv *)malloc(sizeof(struct __xlocale_st_localeconv));
96 + lc->__free_extra = NULL;
97 + if (loc->__lc_localeconv)
98 + lc->__ret = loc->__lc_localeconv->__ret;
100 + loc->__mlocale_changed = 1;
101 + loc->__nlocale_changed = 1;
104 - if (__mlocale_changed) {
105 + if (loc->__mlocale_changed) {
106 /* LC_MONETARY part */
107 struct lc_monetary_T * mptr;
109 -#define M_ASSIGN_STR(NAME) (ret.NAME = (char*)mptr->NAME)
110 -#define M_ASSIGN_CHAR(NAME) (ret.NAME = mptr->NAME[0])
111 +#define M_ASSIGN_STR(NAME) (lc->__ret.NAME = (char*)mptr->NAME)
112 +#define M_ASSIGN_CHAR(NAME) (lc->__ret.NAME = mptr->NAME[0])
114 - mptr = __get_current_monetary_locale();
115 + mptr = __get_current_monetary_locale(loc);
116 M_ASSIGN_STR(int_curr_symbol);
117 M_ASSIGN_STR(currency_symbol);
118 M_ASSIGN_STR(mon_decimal_point);
120 M_ASSIGN_CHAR(int_n_sep_by_space);
121 M_ASSIGN_CHAR(int_p_sign_posn);
122 M_ASSIGN_CHAR(int_n_sign_posn);
123 - __mlocale_changed = 0;
124 + loc->__mlocale_changed = 0;
127 - if (__nlocale_changed) {
128 + if (loc->__nlocale_changed) {
129 /* LC_NUMERIC part */
130 struct lc_numeric_T * nptr;
132 -#define N_ASSIGN_STR(NAME) (ret.NAME = (char*)nptr->NAME)
133 +#define N_ASSIGN_STR(NAME) (lc->__ret.NAME = (char*)nptr->NAME)
135 - nptr = __get_current_numeric_locale();
136 + nptr = __get_current_numeric_locale(loc);
137 N_ASSIGN_STR(decimal_point);
138 N_ASSIGN_STR(thousands_sep);
139 N_ASSIGN_STR(grouping);
140 - __nlocale_changed = 0;
141 + loc->__nlocale_changed = 0;
145 + XL_RELEASE(loc->__lc_localeconv);
146 + loc->__lc_localeconv = lc;
148 + return (&lc->__ret);
152 + * Return the current locale conversion.
157 + /*--------------------------------------------------------------------
158 + * If _onlyClocaleconv is non-zero, just return __lconv, which is a "C"
159 + * struct lconv *. Otherwise, do the normal thing.
160 + *--------------------------------------------------------------------*/
161 + if (_onlyClocaleconv)
163 + return localeconv_l(__current_locale());