]> git.saurik.com Git - apple/libc.git/blob - locale/FreeBSD/euc.c.patch
Libc-763.13.tar.gz
[apple/libc.git] / locale / FreeBSD / euc.c.patch
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
4 #include <sys/param.h>
5 __FBSDID("$FreeBSD: src/lib/libc/locale/euc.c,v 1.22 2007/10/13 16:28:21 ache Exp $");
6
7 +#include "xlocale_private.h"
8 +
9 #include <errno.h>
10 #include <limits.h>
11 #include <runetype.h>
12 @@ -49,13 +51,11 @@ __FBSDID("$FreeBSD: src/lib/libc/locale/
13 #include <wchar.h>
14 #include "mblocal.h"
15
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);
22 +static int _EUC_mbsinit(const mbstate_t *, locale_t);
23 static size_t _EUC_wcrtomb(char * __restrict, wchar_t,
24 - mbstate_t * __restrict);
25 + mbstate_t * __restrict, locale_t);
26
27 typedef struct {
28 int count[4];
29 @@ -69,12 +69,20 @@ typedef struct {
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);
52 @@ -113,24 +121,22 @@ _EUC_init(_RuneLocale *rl)
53 }
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;
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;
68 return (0);
69 }
70
71 static int
72 -_EUC_mbsinit(const mbstate_t *ps)
73 +_EUC_mbsinit(const mbstate_t *ps, locale_t loc __unused)
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
84 @@ -146,16 +152,18 @@ _euc_set(u_int c)
85
86 static size_t
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);
105 @@ -218,11 +226,12 @@ _EUC_mbrtowc(wchar_t * __restrict pwc, c
106 }
107
108 static size_t
109 -_EUC_wcrtomb(char * __restrict s, wchar_t wc, mbstate_t * __restrict ps)
110 +_EUC_wcrtomb(char * __restrict s, wchar_t wc, mbstate_t * __restrict ps, locale_t loc)
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