]> git.saurik.com Git - apple/libc.git/blob - locale/FreeBSD/lnumeric.c.patch
Libc-391.2.10.tar.gz
[apple/libc.git] / locale / FreeBSD / lnumeric.c.patch
1 --- lnumeric.c.orig 2004-11-25 11:38:17.000000000 -0800
2 +++ lnumeric.c 2005-03-16 23:02:09.000000000 -0800
3 @@ -27,12 +27,14 @@
4 #include <sys/cdefs.h>
5 __FBSDID("$FreeBSD: src/lib/libc/locale/lnumeric.c,v 1.16 2003/06/26 10:46:16 phantom Exp $");
6
7 +#include "xlocale_private.h"
8 +
9 #include <limits.h>
10 +#include <string.h>
11
12 #include "ldpart.h"
13 #include "lnumeric.h"
14
15 -extern int __nlocale_changed;
16 extern const char *__fix_locale_grouping_str(const char *);
17
18 #define LCNUMERIC_SIZE (sizeof(struct lc_numeric_T) / sizeof(char *))
19 @@ -45,49 +47,85 @@
20 numempty /* grouping */
21 };
22
23 -static struct lc_numeric_T _numeric_locale;
24 -static int _numeric_using_locale;
25 -static char *_numeric_locale_buf;
26 -
27 -int
28 -__numeric_load_locale(const char *name)
29 +__private_extern__ int
30 +__numeric_load_locale(const char *name, locale_t loc)
31 {
32 int ret;
33 + struct __xlocale_st_numeric *xp;
34 + static struct __xlocale_st_numeric *cache = NULL;
35 +
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);
45 + }
46 +
47 + if (loc->_numeric_using_locale && strcmp(name, loc->__lc_numeric->_numeric_locale_buf) == 0)
48 + return (_LDP_CACHE);
49 + /*
50 + * If the locale name is the same as our cache, use the cache.
51 + */
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);
59 + }
60 + if ((xp = (struct __xlocale_st_numeric *)malloc(sizeof(*xp))) == NULL)
61 + return _LDP_ERROR;
62 + xp->__refcount = 1;
63 + xp->__free_extra = (__free_extra_t)__ldpart_free_extra;
64 + xp->_numeric_locale_buf = NULL;
65
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;
76 + else
77 + free(xp);
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;
91 + XL_RELEASE(cache);
92 + cache = xp;
93 + XL_RETAIN(cache);
94 }
95 return (ret);
96 }
97
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)
102 {
103 - return (_numeric_using_locale
104 - ? &_numeric_locale
105 + return (loc->_numeric_using_locale
106 + ? &loc->__lc_numeric->_numeric_locale
107 : (struct lc_numeric_T *)&_C_numeric_locale);
108 }
109
110 #ifdef LOCALE_DEBUG
111 void
112 numericdebug(void) {
113 +locale_t loc = __current_locale();
114 printf( "decimal_point = %s\n"
115 "thousands_sep = %s\n"
116 "grouping = %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
123 );
124 }
125 #endif /* LOCALE_DEBUG */