]> git.saurik.com Git - apple/libc.git/blob - locale/FreeBSD/euc.c.patch
Libc-594.9.5.tar.gz
[apple/libc.git] / locale / FreeBSD / euc.c.patch
1 --- euc.c.orig Thu Nov 25 11:38:16 2004
2 +++ euc.c Fri Feb 18 15:30:38 2005
3 @@ -41,6 +41,8 @@
4 #include <sys/param.h>
5 __FBSDID("$FreeBSD: src/lib/libc/locale/euc.c,v 1.20 2004/06/23 07:01:43 tjr Exp $");
6
7 +#include "xlocale_private.h"
8 +
9 #include <errno.h>
10 #include <limits.h>
11 #include <runetype.h>
12 @@ -49,11 +51,12 @@
13 #include <wchar.h>
14 #include "mblocal.h"
15
16 -int _EUC_init(_RuneLocale *);
17 -size_t _EUC_mbrtowc(wchar_t * __restrict, const char * __restrict, size_t,
18 - mbstate_t * __restrict);
19 -int _EUC_mbsinit(const mbstate_t *);
20 -size_t _EUC_wcrtomb(char * __restrict, wchar_t, mbstate_t * __restrict);
21 +__private_extern__ int _EUC_init(struct __xlocale_st_runelocale *);
22 +static size_t _EUC_mbrtowc(wchar_t * __restrict, const char * __restrict, size_t,
23 + mbstate_t * __restrict, locale_t);
24 +static int _EUC_mbsinit(const mbstate_t *, locale_t);
25 +static size_t _EUC_wcrtomb(char * __restrict, wchar_t, mbstate_t * __restrict,
26 + locale_t);
27
28 typedef struct {
29 int count[4];
30 @@ -67,12 +70,20 @@
31 int want;
32 } _EucState;
33
34 -int
35 -_EUC_init(_RuneLocale *rl)
36 +/* This will be called by the XL_RELEASE() macro to free the extra storage */
37 +static void
38 +_EUC_free_extra(struct __xlocale_st_runelocale *xrl)
39 +{
40 + free(xrl->_CurrentRuneLocale.__variable);
41 +}
42 +
43 +__private_extern__ int
44 +_EUC_init(struct __xlocale_st_runelocale *xrl)
45 {
46 _EucInfo *ei;
47 int x, new__mb_cur_max;
48 char *v, *e;
49 + _RuneLocale *rl = &xrl->_CurrentRuneLocale;
50
51 if (rl->__variable == NULL)
52 return (EFTYPE);
53 @@ -111,23 +122,21 @@
54 }
55 rl->__variable = ei;
56 rl->__variable_len = sizeof(_EucInfo);
57 - _CurrentRuneLocale = rl;
58 - __mb_cur_max = new__mb_cur_max;
59 - __mbrtowc = _EUC_mbrtowc;
60 - __wcrtomb = _EUC_wcrtomb;
61 - __mbsinit = _EUC_mbsinit;
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->__free_extra = (__free_extra_t)_EUC_free_extra;
67 return (0);
68 }
69
70 -int
71 -_EUC_mbsinit(const mbstate_t *ps)
72 +static int
73 +_EUC_mbsinit(const mbstate_t *ps, locale_t loc)
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 @@ -140,18 +149,20 @@
85 return ((c & 0x80) ? c == _SS3 ? 3 : c == _SS2 ? 2 : 1 : 0);
86 }
87
88 -size_t
89 +static size_t
90 _EUC_mbrtowc(wchar_t * __restrict pwc, const char * __restrict s, size_t n,
91 - mbstate_t * __restrict ps)
92 + mbstate_t * __restrict ps, locale_t loc)
93 {
94 _EucState *es;
95 int i, set, want;
96 wchar_t wc;
97 const char *os;
98 + struct __xlocale_st_runelocale *rl = loc->__lc_ctype;
99 + _EucInfo *CEI = (_EucInfo *)rl->_CurrentRuneLocale.__variable;
100
101 es = (_EucState *)ps;
102
103 - if (es->want < 0 || es->want > MB_CUR_MAX || es->set < 0 ||
104 + if (es->want < 0 || es->want > rl->__mb_cur_max || es->set < 0 ||
105 es->set > 3) {
106 errno = EINVAL;
107 return ((size_t)-1);
108 @@ -213,12 +224,14 @@
109 return (wc == L'\0' ? 0 : s - os);
110 }
111
112 -size_t
113 -_EUC_wcrtomb(char * __restrict s, wchar_t wc, mbstate_t * __restrict ps)
114 +static size_t
115 +_EUC_wcrtomb(char * __restrict s, wchar_t wc, mbstate_t * __restrict ps,
116 + locale_t loc)
117 {
118 _EucState *es;
119 wchar_t m, nm;
120 int i, len;
121 + _EucInfo *CEI = (_EucInfo *)loc->__lc_ctype->_CurrentRuneLocale.__variable;
122
123 es = (_EucState *)ps;
124