]> git.saurik.com Git - apple/libc.git/blame_incremental - locale/FreeBSD/lnumeric.c.patch
Libc-763.11.tar.gz
[apple/libc.git] / locale / FreeBSD / lnumeric.c.patch
... / ...
CommitLineData
1--- lnumeric.c.orig 2009-11-09 15:05:25.000000000 -0800
2+++ lnumeric.c 2009-11-09 15:05:25.000000000 -0800
3@@ -27,67 +27,103 @@
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
20-static char numempty[] = { CHAR_MAX, '\0' };
21-
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]*/
27 };
28
29-static struct lc_numeric_T _numeric_locale;
30-static int _numeric_using_locale;
31-static char *_numeric_locale_buf;
32-
33-int
34-__numeric_load_locale(const char *name)
35+__private_extern__ int
36+__numeric_load_locale(const char *name, locale_t loc)
37 {
38 int ret;
39+ struct __xlocale_st_numeric *xp;
40+ static struct __xlocale_st_numeric *cache = NULL;
41+
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);
51+ }
52+
53+ if (loc->_numeric_using_locale && strcmp(name, loc->__lc_numeric->_numeric_locale_buf) == 0)
54+ return (_LDP_CACHE);
55+ /*
56+ * If the locale name is the same as our cache, use the cache.
57+ */
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);
65+ }
66+ if ((xp = (struct __xlocale_st_numeric *)malloc(sizeof(*xp))) == NULL)
67+ return _LDP_ERROR;
68+ xp->__refcount = 1;
69+ xp->__free_extra = (__free_extra_t)__ldpart_free_extra;
70+ xp->_numeric_locale_buf = NULL;
71
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;
82+ else
83+ free(xp);
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;
97+ XL_RELEASE(cache);
98+ cache = xp;
99+ XL_RETAIN(cache);
100 }
101 return (ret);
102 }
103
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)
108 {
109- return (_numeric_using_locale
110- ? &_numeric_locale
111+ return (loc->_numeric_using_locale
112+ ? &loc->__lc_numeric->_numeric_locale
113 : (struct lc_numeric_T *)&_C_numeric_locale);
114 }
115
116 #ifdef LOCALE_DEBUG
117 void
118 numericdebug(void) {
119+locale_t loc = __current_locale();
120 printf( "decimal_point = %s\n"
121 "thousands_sep = %s\n"
122 "grouping = %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
129 );
130 }
131 #endif /* LOCALE_DEBUG */