1 --- lnumeric.c.orig 2009-11-09 15:05:25.000000000 -0800
2 +++ lnumeric.c 2009-11-09 15:05:25.000000000 -0800
5 __FBSDID("$FreeBSD: src/lib/libc/locale/lnumeric.c,v 1.16 2003/06/26 10:46:16 phantom Exp $");
7 +#include "xlocale_private.h"
15 -extern int __nlocale_changed;
16 extern const char *__fix_locale_grouping_str(const char *);
18 #define LCNUMERIC_SIZE (sizeof(struct lc_numeric_T) / sizeof(char *))
20 -static char numempty[] = { CHAR_MAX, '\0' };
22 static const struct lc_numeric_T _C_numeric_locale = {
23 ".", /* decimal_point */
24 "", /* thousands_sep */
25 - numempty /* grouping */
26 + "" /* grouping [C99 7.11.2.1]*/
29 -static struct lc_numeric_T _numeric_locale;
30 -static int _numeric_using_locale;
31 -static char *_numeric_locale_buf;
34 -__numeric_load_locale(const char *name)
35 +__private_extern__ int
36 +__numeric_load_locale(const char *name, locale_t loc)
39 + struct __xlocale_st_numeric *xp;
40 + static struct __xlocale_st_numeric *cache = NULL;
42 + /* 'name' must be already checked. */
43 + if (strcmp(name, "C") == 0 || strcmp(name, "POSIX") == 0) {
44 + if (!loc->_numeric_using_locale)
45 + return (_LDP_CACHE);
46 + loc->_numeric_using_locale = 0;
47 + XL_RELEASE(loc->__lc_numeric);
48 + loc->__lc_numeric = NULL;
49 + loc->__nlocale_changed = 1;
50 + return (_LDP_CACHE);
53 + if (loc->_numeric_using_locale && strcmp(name, loc->__lc_numeric->_numeric_locale_buf) == 0)
54 + return (_LDP_CACHE);
56 + * If the locale name is the same as our cache, use the cache.
58 + if (cache && cache->_numeric_locale_buf && strcmp(name, cache->_numeric_locale_buf) == 0) {
59 + loc->_numeric_using_locale = 1;
60 + XL_RELEASE(loc->__lc_numeric);
61 + loc->__lc_numeric = cache;
62 + XL_RETAIN(loc->__lc_numeric);
63 + loc->__nlocale_changed = 1;
64 + return (_LDP_CACHE);
66 + if ((xp = (struct __xlocale_st_numeric *)malloc(sizeof(*xp))) == NULL)
69 + xp->__free_extra = (__free_extra_t)__ldpart_free_extra;
70 + xp->_numeric_locale_buf = NULL;
72 - ret = __part_load_locale(name, &_numeric_using_locale,
73 - &_numeric_locale_buf, "LC_NUMERIC",
74 + ret = __part_load_locale(name, &loc->_numeric_using_locale,
75 + &xp->_numeric_locale_buf, "LC_NUMERIC",
76 LCNUMERIC_SIZE, LCNUMERIC_SIZE,
77 - (const char **)&_numeric_locale);
78 + (const char **)&xp->_numeric_locale);
79 if (ret != _LDP_ERROR)
80 - __nlocale_changed = 1;
81 + loc->__nlocale_changed = 1;
84 if (ret == _LDP_LOADED) {
85 /* Can't be empty according to C99 */
86 - if (*_numeric_locale.decimal_point == '\0')
87 - _numeric_locale.decimal_point =
88 + if (*xp->_numeric_locale.decimal_point == '\0')
89 + xp->_numeric_locale.decimal_point =
90 _C_numeric_locale.decimal_point;
91 - _numeric_locale.grouping =
92 - __fix_locale_grouping_str(_numeric_locale.grouping);
93 + xp->_numeric_locale.grouping =
94 + __fix_locale_grouping_str(xp->_numeric_locale.grouping);
95 + XL_RELEASE(loc->__lc_numeric);
96 + loc->__lc_numeric = xp;
104 -struct lc_numeric_T *
105 -__get_current_numeric_locale(void)
106 +__private_extern__ struct lc_numeric_T *
107 +__get_current_numeric_locale(locale_t loc)
109 - return (_numeric_using_locale
111 + return (loc->_numeric_using_locale
112 + ? &loc->__lc_numeric->_numeric_locale
113 : (struct lc_numeric_T *)&_C_numeric_locale);
119 +locale_t loc = __current_locale();
120 printf( "decimal_point = %s\n"
121 "thousands_sep = %s\n"
123 - _numeric_locale.decimal_point,
124 - _numeric_locale.thousands_sep,
125 - _numeric_locale.grouping
126 + loc->__lc_numeric->_numeric_locale.decimal_point,
127 + loc->__lc_numeric->_numeric_locale.thousands_sep,
128 + loc->__lc_numeric->_numeric_locale.grouping
131 #endif /* LOCALE_DEBUG */