1 --- lnumeric.c.orig 2004-11-25 11:38:17.000000000 -0800
2 +++ lnumeric.c 2005-03-16 23:02:09.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 numempty /* grouping */
23 -static struct lc_numeric_T _numeric_locale;
24 -static int _numeric_using_locale;
25 -static char *_numeric_locale_buf;
28 -__numeric_load_locale(const char *name)
29 +__private_extern__ int
30 +__numeric_load_locale(const char *name, locale_t loc)
33 + struct __xlocale_st_numeric *xp;
34 + static struct __xlocale_st_numeric *cache = NULL;
36 + /* 'name' must be already checked. */
37 + if (strcmp(name, "C") == 0 || strcmp(name, "POSIX") == 0) {
38 + if (!loc->_numeric_using_locale)
39 + return (_LDP_CACHE);
40 + loc->_numeric_using_locale = 0;
41 + XL_RELEASE(loc->__lc_numeric);
42 + loc->__lc_numeric = NULL;
43 + loc->__nlocale_changed = 1;
44 + return (_LDP_CACHE);
47 + if (loc->_numeric_using_locale && strcmp(name, loc->__lc_numeric->_numeric_locale_buf) == 0)
48 + return (_LDP_CACHE);
50 + * If the locale name is the same as our cache, use the cache.
52 + if (cache && cache->_numeric_locale_buf && strcmp(name, cache->_numeric_locale_buf) == 0) {
53 + loc->_numeric_using_locale = 1;
54 + XL_RELEASE(loc->__lc_numeric);
55 + loc->__lc_numeric = cache;
56 + XL_RETAIN(loc->__lc_numeric);
57 + loc->__nlocale_changed = 1;
58 + return (_LDP_CACHE);
60 + if ((xp = (struct __xlocale_st_numeric *)malloc(sizeof(*xp))) == NULL)
63 + xp->__free_extra = (__free_extra_t)__ldpart_free_extra;
64 + xp->_numeric_locale_buf = NULL;
66 - ret = __part_load_locale(name, &_numeric_using_locale,
67 - &_numeric_locale_buf, "LC_NUMERIC",
68 + ret = __part_load_locale(name, &loc->_numeric_using_locale,
69 + &xp->_numeric_locale_buf, "LC_NUMERIC",
70 LCNUMERIC_SIZE, LCNUMERIC_SIZE,
71 - (const char **)&_numeric_locale);
72 + (const char **)&xp->_numeric_locale);
73 if (ret != _LDP_ERROR)
74 - __nlocale_changed = 1;
75 + loc->__nlocale_changed = 1;
78 if (ret == _LDP_LOADED) {
79 /* Can't be empty according to C99 */
80 - if (*_numeric_locale.decimal_point == '\0')
81 - _numeric_locale.decimal_point =
82 + if (*xp->_numeric_locale.decimal_point == '\0')
83 + xp->_numeric_locale.decimal_point =
84 _C_numeric_locale.decimal_point;
85 - _numeric_locale.grouping =
86 - __fix_locale_grouping_str(_numeric_locale.grouping);
87 + xp->_numeric_locale.grouping =
88 + __fix_locale_grouping_str(xp->_numeric_locale.grouping);
89 + XL_RELEASE(loc->__lc_numeric);
90 + loc->__lc_numeric = xp;
98 -struct lc_numeric_T *
99 -__get_current_numeric_locale(void)
100 +__private_extern__ struct lc_numeric_T *
101 +__get_current_numeric_locale(locale_t loc)
103 - return (_numeric_using_locale
105 + return (loc->_numeric_using_locale
106 + ? &loc->__lc_numeric->_numeric_locale
107 : (struct lc_numeric_T *)&_C_numeric_locale);
113 +locale_t loc = __current_locale();
114 printf( "decimal_point = %s\n"
115 "thousands_sep = %s\n"
117 - _numeric_locale.decimal_point,
118 - _numeric_locale.thousands_sep,
119 - _numeric_locale.grouping
120 + loc->__lc_numeric->_numeric_locale.decimal_point,
121 + loc->__lc_numeric->_numeric_locale.thousands_sep,
122 + loc->__lc_numeric->_numeric_locale.grouping
125 #endif /* LOCALE_DEBUG */