]>
Commit | Line | Data |
---|---|---|
1f2f436a A |
1 | --- euc.c.bsdnew 2009-11-09 15:05:25.000000000 -0800 |
2 | +++ euc.c 2009-11-09 15:44:21.000000000 -0800 | |
3 | @@ -41,6 +41,8 @@ static char sccsid[] = "@(#)euc.c 8.1 (B | |
3d9156a7 | 4 | #include <sys/param.h> |
1f2f436a | 5 | __FBSDID("$FreeBSD: src/lib/libc/locale/euc.c,v 1.22 2007/10/13 16:28:21 ache Exp $"); |
3d9156a7 A |
6 | |
7 | +#include "xlocale_private.h" | |
8 | + | |
9 | #include <errno.h> | |
10 | #include <limits.h> | |
11 | #include <runetype.h> | |
1f2f436a | 12 | @@ -49,13 +51,11 @@ __FBSDID("$FreeBSD: src/lib/libc/locale/ |
3d9156a7 A |
13 | #include <wchar.h> |
14 | #include "mblocal.h" | |
15 | ||
1f2f436a A |
16 | -extern int __mb_sb_limit; |
17 | - | |
18 | static size_t _EUC_mbrtowc(wchar_t * __restrict, const char * __restrict, | |
19 | - size_t, mbstate_t * __restrict); | |
20 | -static int _EUC_mbsinit(const mbstate_t *); | |
21 | + size_t, mbstate_t * __restrict, locale_t); | |
3d9156a7 | 22 | +static int _EUC_mbsinit(const mbstate_t *, locale_t); |
1f2f436a A |
23 | static size_t _EUC_wcrtomb(char * __restrict, wchar_t, |
24 | - mbstate_t * __restrict); | |
25 | + mbstate_t * __restrict, locale_t); | |
3d9156a7 A |
26 | |
27 | typedef struct { | |
28 | int count[4]; | |
1f2f436a | 29 | @@ -69,12 +69,20 @@ typedef struct { |
3d9156a7 A |
30 | int want; |
31 | } _EucState; | |
32 | ||
33 | -int | |
34 | -_EUC_init(_RuneLocale *rl) | |
35 | +/* This will be called by the XL_RELEASE() macro to free the extra storage */ | |
36 | +static void | |
37 | +_EUC_free_extra(struct __xlocale_st_runelocale *xrl) | |
38 | +{ | |
39 | + free(xrl->_CurrentRuneLocale.__variable); | |
40 | +} | |
41 | + | |
42 | +__private_extern__ int | |
43 | +_EUC_init(struct __xlocale_st_runelocale *xrl) | |
44 | { | |
45 | _EucInfo *ei; | |
46 | int x, new__mb_cur_max; | |
47 | char *v, *e; | |
48 | + _RuneLocale *rl = &xrl->_CurrentRuneLocale; | |
49 | ||
50 | if (rl->__variable == NULL) | |
51 | return (EFTYPE); | |
1f2f436a | 52 | @@ -113,24 +121,22 @@ _EUC_init(_RuneLocale *rl) |
9385eb3d | 53 | } |
3d9156a7 A |
54 | rl->__variable = ei; |
55 | rl->__variable_len = sizeof(_EucInfo); | |
56 | - _CurrentRuneLocale = rl; | |
57 | - __mb_cur_max = new__mb_cur_max; | |
58 | - __mbrtowc = _EUC_mbrtowc; | |
59 | - __wcrtomb = _EUC_wcrtomb; | |
60 | - __mbsinit = _EUC_mbsinit; | |
1f2f436a A |
61 | - __mb_sb_limit = 256; |
62 | + xrl->__mb_cur_max = new__mb_cur_max; | |
63 | + xrl->__mbrtowc = _EUC_mbrtowc; | |
64 | + xrl->__wcrtomb = _EUC_wcrtomb; | |
65 | + xrl->__mbsinit = _EUC_mbsinit; | |
66 | + xrl->__mb_sb_limit = 256; | |
67 | + xrl->__free_extra = (__free_extra_t)_EUC_free_extra; | |
3d9156a7 A |
68 | return (0); |
69 | } | |
70 | ||
1f2f436a | 71 | static int |
3d9156a7 | 72 | -_EUC_mbsinit(const mbstate_t *ps) |
1f2f436a | 73 | +_EUC_mbsinit(const mbstate_t *ps, locale_t loc __unused) |
3d9156a7 A |
74 | { |
75 | ||
76 | return (ps == NULL || ((const _EucState *)ps)->want == 0); | |
77 | } | |
78 | ||
79 | -#define CEI ((_EucInfo *)(_CurrentRuneLocale->__variable)) | |
80 | - | |
81 | #define _SS2 0x008e | |
82 | #define _SS3 0x008f | |
83 | ||
1f2f436a | 84 | @@ -146,16 +152,18 @@ _euc_set(u_int c) |
3d9156a7 | 85 | |
1f2f436a | 86 | static size_t |
3d9156a7 A |
87 | _EUC_mbrtowc(wchar_t * __restrict pwc, const char * __restrict s, size_t n, |
88 | - mbstate_t * __restrict ps) | |
89 | + mbstate_t * __restrict ps, locale_t loc) | |
90 | { | |
91 | _EucState *es; | |
92 | int i, set, want; | |
93 | wchar_t wc; | |
94 | const char *os; | |
95 | + struct __xlocale_st_runelocale *rl = loc->__lc_ctype; | |
96 | + _EucInfo *CEI = (_EucInfo *)rl->_CurrentRuneLocale.__variable; | |
97 | ||
98 | es = (_EucState *)ps; | |
99 | ||
100 | - if (es->want < 0 || es->want > MB_CUR_MAX || es->set < 0 || | |
101 | + if (es->want < 0 || es->want > rl->__mb_cur_max || es->set < 0 || | |
102 | es->set > 3) { | |
103 | errno = EINVAL; | |
104 | return ((size_t)-1); | |
1f2f436a | 105 | @@ -218,11 +226,12 @@ _EUC_mbrtowc(wchar_t * __restrict pwc, c |
3d9156a7 A |
106 | } |
107 | ||
1f2f436a | 108 | static size_t |
3d9156a7 | 109 | -_EUC_wcrtomb(char * __restrict s, wchar_t wc, mbstate_t * __restrict ps) |
1f2f436a | 110 | +_EUC_wcrtomb(char * __restrict s, wchar_t wc, mbstate_t * __restrict ps, locale_t loc) |
3d9156a7 A |
111 | { |
112 | _EucState *es; | |
113 | wchar_t m, nm; | |
114 | int i, len; | |
115 | + _EucInfo *CEI = (_EucInfo *)loc->__lc_ctype->_CurrentRuneLocale.__variable; | |
116 | ||
117 | es = (_EucState *)ps; | |
118 |