]>
Commit | Line | Data |
---|---|---|
3d9156a7 A |
1 | --- localeconv.c.orig 2004-11-25 11:38:18.000000000 -0800 |
2 | +++ localeconv.c 2005-02-17 23:35:43.000000000 -0800 | |
3 | @@ -38,11 +38,69 @@ | |
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 | ||
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' }; | |
23 | + | |
24 | +/* | |
25 | + * Default (C) locale conversion. | |
26 | + */ | |
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 */ | |
52 | +}; | |
53 | +static int _onlyClocaleconv = 0; | |
54 | + | |
55 | +int | |
56 | +__getonlyClocaleconv(void) | |
57 | +{ | |
58 | + return _onlyClocaleconv; | |
59 | +} | |
60 | + | |
61 | +int | |
62 | +__setonlyClocaleconv(int val) | |
63 | +{ | |
64 | + int prev = _onlyClocaleconv; | |
65 | + | |
66 | + _onlyClocaleconv = val; | |
67 | + return prev; | |
68 | +} | |
69 | + | |
70 | /* | |
71 | * The localeconv() function constructs a struct lconv from the current | |
72 | * monetary and numeric locales. | |
3d9156a7 A |
73 | @@ -52,25 +110,37 @@ |
74 | * lconv structure are computed only when the monetary or numeric | |
75 | * locale has been changed. | |
76 | */ | |
77 | -int __mlocale_changed = 1; | |
78 | -int __nlocale_changed = 1; | |
79 | ||
80 | /* | |
81 | * Return the current locale conversion. | |
82 | */ | |
83 | struct lconv * | |
84 | -localeconv() | |
85 | +localeconv_l(locale_t loc) | |
9385eb3d | 86 | { |
3d9156a7 A |
87 | - static struct lconv ret; |
88 | + struct __xlocale_st_localeconv *lc; | |
89 | + | |
90 | + NORMALIZE_LOCALE(loc); | |
91 | + if (loc->__lc_localeconv && !loc->__mlocale_changed && !loc->__nlocale_changed) | |
92 | + return &loc->__lc_localeconv->__ret; | |
93 | + | |
94 | + lc = (struct __xlocale_st_localeconv *)malloc(sizeof(struct __xlocale_st_localeconv)); | |
95 | + lc->__refcount = 1; | |
96 | + lc->__free_extra = NULL; | |
97 | + if (loc->__lc_localeconv) | |
98 | + lc->__ret = loc->__lc_localeconv->__ret; | |
99 | + else { | |
100 | + loc->__mlocale_changed = 1; | |
101 | + loc->__nlocale_changed = 1; | |
102 | + } | |
103 | ||
104 | - if (__mlocale_changed) { | |
105 | + if (loc->__mlocale_changed) { | |
106 | /* LC_MONETARY part */ | |
107 | struct lc_monetary_T * mptr; | |
108 | ||
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]) | |
113 | ||
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); | |
119 | @@ -92,21 +162,39 @@ | |
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; | |
125 | } | |
126 | ||
127 | - if (__nlocale_changed) { | |
128 | + if (loc->__nlocale_changed) { | |
129 | /* LC_NUMERIC part */ | |
130 | struct lc_numeric_T * nptr; | |
131 | ||
132 | -#define N_ASSIGN_STR(NAME) (ret.NAME = (char*)nptr->NAME) | |
133 | +#define N_ASSIGN_STR(NAME) (lc->__ret.NAME = (char*)nptr->NAME) | |
134 | ||
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; | |
142 | } | |
143 | ||
144 | - return (&ret); | |
145 | + XL_RELEASE(loc->__lc_localeconv); | |
146 | + loc->__lc_localeconv = lc; | |
147 | + | |
148 | + return (&lc->__ret); | |
149 | +} | |
9385eb3d | 150 | + |
3d9156a7 A |
151 | +/* |
152 | + * Return the current locale conversion. | |
153 | + */ | |
154 | +struct lconv * | |
155 | +localeconv() | |
156 | +{ | |
9385eb3d A |
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) | |
162 | + return &_C_lconv; | |
3d9156a7 A |
163 | + return localeconv_l(__current_locale()); |
164 | } |