1 --- lmonetary.c.orig 2004-11-25 11:38:17.000000000 -0800
2 +++ lmonetary.c 2005-03-16 23:01:33.000000000 -0800
5 __FBSDID("$FreeBSD: src/lib/libc/locale/lmonetary.c,v 1.19 2003/06/26 10:46:16 phantom Exp $");
7 +#include "xlocale_private.h"
15 #include "lmonetary.h"
17 -extern int __mlocale_changed;
18 extern const char * __fix_locale_grouping_str(const char *);
20 #define LCMONETARY_SIZE_FULL (sizeof(struct lc_monetary_T) / sizeof(char *))
22 numempty /* int_n_sign_posn */
25 -static struct lc_monetary_T _monetary_locale;
26 -static int _monetary_using_locale;
27 -static char *_monetary_locale_buf;
37 -__monetary_load_locale(const char *name)
38 +__private_extern__ int
39 +__monetary_load_locale(const char *name, locale_t loc)
42 + struct __xlocale_st_monetary *xp;
43 + static struct __xlocale_st_monetary *cache = NULL;
45 + /* 'name' must be already checked. */
46 + if (strcmp(name, "C") == 0 || strcmp(name, "POSIX") == 0) {
47 + if (!loc->_monetary_using_locale)
48 + return (_LDP_CACHE);
49 + loc->_monetary_using_locale = 0;
50 + XL_RELEASE(loc->__lc_monetary);
51 + loc->__lc_monetary = NULL;
52 + loc->__mlocale_changed = 1;
53 + return (_LDP_CACHE);
56 + if (loc->_monetary_using_locale && strcmp(name, loc->__lc_monetary->_monetary_locale_buf) == 0)
57 + return (_LDP_CACHE);
59 + * If the locale name is the same as our cache, use the cache.
61 + if (cache && cache->_monetary_locale_buf && strcmp(name, cache->_monetary_locale_buf) == 0) {
62 + loc->_monetary_using_locale = 1;
63 + XL_RELEASE(loc->__lc_monetary);
64 + loc->__lc_monetary = cache;
65 + XL_RETAIN(loc->__lc_monetary);
66 + loc->__mlocale_changed = 1;
67 + return (_LDP_CACHE);
69 + if ((xp = (struct __xlocale_st_monetary *)malloc(sizeof(*xp))) == NULL)
72 + xp->__free_extra = (__free_extra_t)__ldpart_free_extra;
73 + xp->_monetary_locale_buf = NULL;
75 - ret = __part_load_locale(name, &_monetary_using_locale,
76 - &_monetary_locale_buf, "LC_MONETARY",
77 + ret = __part_load_locale(name, &loc->_monetary_using_locale,
78 + &xp->_monetary_locale_buf, "LC_MONETARY",
79 LCMONETARY_SIZE_FULL, LCMONETARY_SIZE_MIN,
80 - (const char **)&_monetary_locale);
81 + (const char **)&xp->_monetary_locale);
82 if (ret != _LDP_ERROR)
83 - __mlocale_changed = 1;
84 + loc->__mlocale_changed = 1;
87 if (ret == _LDP_LOADED) {
88 - _monetary_locale.mon_grouping =
89 - __fix_locale_grouping_str(_monetary_locale.mon_grouping);
90 + xp->_monetary_locale.mon_grouping =
91 + __fix_locale_grouping_str(xp->_monetary_locale.mon_grouping);
93 -#define M_ASSIGN_CHAR(NAME) (((char *)_monetary_locale.NAME)[0] = \
94 - cnv(_monetary_locale.NAME))
95 +#define M_ASSIGN_CHAR(NAME) (((char *)xp->_monetary_locale.NAME)[0] = \
96 + cnv(xp->_monetary_locale.NAME))
98 M_ASSIGN_CHAR(int_frac_digits);
99 M_ASSIGN_CHAR(frac_digits);
102 #define M_ASSIGN_ICHAR(NAME) \
104 - if (_monetary_locale.int_##NAME == NULL) \
105 - _monetary_locale.int_##NAME = \
106 - _monetary_locale.NAME; \
107 + if (xp->_monetary_locale.int_##NAME == NULL) \
108 + xp->_monetary_locale.int_##NAME = \
109 + xp->_monetary_locale.NAME; \
111 M_ASSIGN_CHAR(int_##NAME); \
113 @@ -130,21 +162,27 @@
114 M_ASSIGN_ICHAR(n_sep_by_space);
115 M_ASSIGN_ICHAR(p_sign_posn);
116 M_ASSIGN_ICHAR(n_sign_posn);
117 + XL_RELEASE(loc->__lc_monetary);
118 + loc->__lc_monetary = xp;
126 -struct lc_monetary_T *
127 -__get_current_monetary_locale(void)
128 +__private_extern__ struct lc_monetary_T *
129 +__get_current_monetary_locale(locale_t loc)
131 - return (_monetary_using_locale
132 - ? &_monetary_locale
133 + return (loc->_monetary_using_locale
134 + ? &loc->__lc_monetary->_monetary_locale
135 : (struct lc_monetary_T *)&_C_monetary_locale);
141 +locale_t loc = __current_locale();
142 printf( "int_curr_symbol = %s\n"
143 "currency_symbol = %s\n"
144 "mon_decimal_point = %s\n"
145 @@ -166,27 +204,27 @@
146 "int_n_sep_by_space = %d\n"
147 "int_p_sign_posn = %d\n"
148 "int_n_sign_posn = %d\n",
149 - _monetary_locale.int_curr_symbol,
150 - _monetary_locale.currency_symbol,
151 - _monetary_locale.mon_decimal_point,
152 - _monetary_locale.mon_thousands_sep,
153 - _monetary_locale.mon_grouping,
154 - _monetary_locale.positive_sign,
155 - _monetary_locale.negative_sign,
156 - _monetary_locale.int_frac_digits[0],
157 - _monetary_locale.frac_digits[0],
158 - _monetary_locale.p_cs_precedes[0],
159 - _monetary_locale.p_sep_by_space[0],
160 - _monetary_locale.n_cs_precedes[0],
161 - _monetary_locale.n_sep_by_space[0],
162 - _monetary_locale.p_sign_posn[0],
163 - _monetary_locale.n_sign_posn[0],
164 - _monetary_locale.int_p_cs_precedes[0],
165 - _monetary_locale.int_p_sep_by_space[0],
166 - _monetary_locale.int_n_cs_precedes[0],
167 - _monetary_locale.int_n_sep_by_space[0],
168 - _monetary_locale.int_p_sign_posn[0],
169 - _monetary_locale.int_n_sign_posn[0]
170 + loc->__lc_monetary->_monetary_locale.int_curr_symbol,
171 + loc->__lc_monetary->_monetary_locale.currency_symbol,
172 + loc->__lc_monetary->_monetary_locale.mon_decimal_point,
173 + loc->__lc_monetary->_monetary_locale.mon_thousands_sep,
174 + loc->__lc_monetary->_monetary_locale.mon_grouping,
175 + loc->__lc_monetary->_monetary_locale.positive_sign,
176 + loc->__lc_monetary->_monetary_locale.negative_sign,
177 + loc->__lc_monetary->_monetary_locale.int_frac_digits[0],
178 + loc->__lc_monetary->_monetary_locale.frac_digits[0],
179 + loc->__lc_monetary->_monetary_locale.p_cs_precedes[0],
180 + loc->__lc_monetary->_monetary_locale.p_sep_by_space[0],
181 + loc->__lc_monetary->_monetary_locale.n_cs_precedes[0],
182 + loc->__lc_monetary->_monetary_locale.n_sep_by_space[0],
183 + loc->__lc_monetary->_monetary_locale.p_sign_posn[0],
184 + loc->__lc_monetary->_monetary_locale.n_sign_posn[0],
185 + loc->__lc_monetary->_monetary_locale.int_p_cs_precedes[0],
186 + loc->__lc_monetary->_monetary_locale.int_p_sep_by_space[0],
187 + loc->__lc_monetary->_monetary_locale.int_n_cs_precedes[0],
188 + loc->__lc_monetary->_monetary_locale.int_n_sep_by_space[0],
189 + loc->__lc_monetary->_monetary_locale.int_p_sign_posn[0],
190 + loc->__lc_monetary->_monetary_locale.int_n_sign_posn[0]
193 #endif /* LOCALE_DEBUG */