]> git.saurik.com Git - apple/libc.git/blob - locale/FreeBSD/utf8.c.patch
Libc-391.tar.gz
[apple/libc.git] / locale / FreeBSD / utf8.c.patch
1 --- utf8.c.orig Thu Nov 25 11:38:20 2004
2 +++ utf8.c Fri Feb 18 15:40:44 2005
3 @@ -27,6 +27,8 @@
4 #include <sys/param.h>
5 __FBSDID("$FreeBSD: src/lib/libc/locale/utf8.c,v 1.11 2004/07/27 06:29:48 tjr Exp $");
6
7 +#include "xlocale_private.h"
8 +
9 #include <errno.h>
10 #include <limits.h>
11 #include <runetype.h>
12 @@ -35,14 +37,16 @@
13 #include <wchar.h>
14 #include "mblocal.h"
15
16 -size_t _UTF8_mbrtowc(wchar_t * __restrict, const char * __restrict, size_t,
17 - mbstate_t * __restrict);
18 -int _UTF8_mbsinit(const mbstate_t *);
19 -size_t _UTF8_mbsnrtowcs(wchar_t * __restrict, const char ** __restrict,
20 - size_t, size_t, mbstate_t * __restrict);
21 -size_t _UTF8_wcrtomb(char * __restrict, wchar_t, mbstate_t * __restrict);
22 -size_t _UTF8_wcsnrtombs(char * __restrict, const wchar_t ** __restrict,
23 - size_t, size_t, mbstate_t * __restrict);
24 +#define UTF8_MB_CUR_MAX 6
25 +
26 +static size_t _UTF8_mbrtowc(wchar_t * __restrict, const char * __restrict, size_t,
27 + mbstate_t * __restrict, locale_t);
28 +static int _UTF8_mbsinit(const mbstate_t *, locale_t);
29 +static size_t _UTF8_mbsnrtowcs(wchar_t * __restrict, const char ** __restrict,
30 + size_t, size_t, mbstate_t * __restrict, locale_t);
31 +static size_t _UTF8_wcrtomb(char * __restrict, wchar_t, mbstate_t * __restrict, locale_t);
32 +static size_t _UTF8_wcsnrtombs(char * __restrict, const wchar_t ** __restrict,
33 + size_t, size_t, mbstate_t * __restrict, locale_t);
34
35 typedef struct {
36 wchar_t ch;
37 @@ -50,31 +54,30 @@
38 wchar_t lbound;
39 } _UTF8State;
40
41 -int
42 -_UTF8_init(_RuneLocale *rl)
43 +__private_extern__ int
44 +_UTF8_init(struct __xlocale_st_runelocale *xrl)
45 {
46
47 - __mbrtowc = _UTF8_mbrtowc;
48 - __wcrtomb = _UTF8_wcrtomb;
49 - __mbsinit = _UTF8_mbsinit;
50 - __mbsnrtowcs = _UTF8_mbsnrtowcs;
51 - __wcsnrtombs = _UTF8_wcsnrtombs;
52 - _CurrentRuneLocale = rl;
53 - __mb_cur_max = 6;
54 + xrl->__mbrtowc = _UTF8_mbrtowc;
55 + xrl->__wcrtomb = _UTF8_wcrtomb;
56 + xrl->__mbsinit = _UTF8_mbsinit;
57 + xrl->__mbsnrtowcs = _UTF8_mbsnrtowcs;
58 + xrl->__wcsnrtombs = _UTF8_wcsnrtombs;
59 + xrl->__mb_cur_max = UTF8_MB_CUR_MAX;
60
61 return (0);
62 }
63
64 -int
65 -_UTF8_mbsinit(const mbstate_t *ps)
66 +static int
67 +_UTF8_mbsinit(const mbstate_t *ps, locale_t loc)
68 {
69
70 return (ps == NULL || ((const _UTF8State *)ps)->want == 0);
71 }
72
73 -size_t
74 +static size_t
75 _UTF8_mbrtowc(wchar_t * __restrict pwc, const char * __restrict s, size_t n,
76 - mbstate_t * __restrict ps)
77 + mbstate_t * __restrict ps, locale_t loc)
78 {
79 _UTF8State *us;
80 int ch, i, mask, want;
81 @@ -194,9 +197,9 @@
82 return (wch == L'\0' ? 0 : want);
83 }
84
85 -size_t
86 +static size_t
87 _UTF8_mbsnrtowcs(wchar_t * __restrict dst, const char ** __restrict src,
88 - size_t nms, size_t len, mbstate_t * __restrict ps)
89 + size_t nms, size_t len, mbstate_t * __restrict ps, locale_t loc)
90 {
91 _UTF8State *us;
92 const char *s;
93 @@ -226,7 +229,7 @@
94 * excluding NUL.
95 */
96 nb = 1;
97 - else if ((nb = _UTF8_mbrtowc(&wc, s, nms, ps)) ==
98 + else if ((nb = _UTF8_mbrtowc(&wc, s, nms, ps, loc)) ==
99 (size_t)-1)
100 /* Invalid sequence - mbrtowc() sets errno. */
101 return ((size_t)-1);
102 @@ -256,7 +259,7 @@
103 */
104 *dst = (wchar_t)*s;
105 nb = 1;
106 - } else if ((nb = _UTF8_mbrtowc(dst, s, nms, ps)) ==
107 + } else if ((nb = _UTF8_mbrtowc(dst, s, nms, ps, loc)) ==
108 (size_t)-1) {
109 *src = s;
110 return ((size_t)-1);
111 @@ -276,8 +279,8 @@
112 return (nchr);
113 }
114
115 -size_t
116 -_UTF8_wcrtomb(char * __restrict s, wchar_t wc, mbstate_t * __restrict ps)
117 +static size_t
118 +_UTF8_wcrtomb(char * __restrict s, wchar_t wc, mbstate_t * __restrict ps, locale_t loc)
119 {
120 _UTF8State *us;
121 unsigned char lead;
122 @@ -344,9 +347,9 @@
123 return (len);
124 }
125
126 -size_t
127 +static size_t
128 _UTF8_wcsnrtombs(char * __restrict dst, const wchar_t ** __restrict src,
129 - size_t nwc, size_t len, mbstate_t * __restrict ps)
130 + size_t nwc, size_t len, mbstate_t * __restrict ps, locale_t loc)
131 {
132 _UTF8State *us;
133 char buf[MB_LEN_MAX];
134 @@ -369,7 +372,7 @@
135 if (0 <= *s && *s < 0x80)
136 /* Fast path for plain ASCII characters. */
137 nb = 1;
138 - else if ((nb = _UTF8_wcrtomb(buf, *s, ps)) ==
139 + else if ((nb = _UTF8_wcrtomb(buf, *s, ps, loc)) ==
140 (size_t)-1)
141 /* Invalid character - wcrtomb() sets errno. */
142 return ((size_t)-1);
143 @@ -386,9 +389,9 @@
144 /* Fast path for plain ASCII characters. */
145 nb = 1;
146 *dst = *s;
147 - } else if (len > (size_t)MB_CUR_MAX) {
148 + } else if (len > (size_t)UTF8_MB_CUR_MAX) {
149 /* Enough space to translate in-place. */
150 - if ((nb = (int)_UTF8_wcrtomb(dst, *s, ps)) < 0) {
151 + if ((nb = (int)_UTF8_wcrtomb(dst, *s, ps, loc)) < 0) {
152 *src = s;
153 return ((size_t)-1);
154 }
155 @@ -396,7 +399,7 @@
156 /*
157 * May not be enough space; use temp. buffer.
158 */
159 - if ((nb = (int)_UTF8_wcrtomb(buf, *s, ps)) < 0) {
160 + if ((nb = (int)_UTF8_wcrtomb(buf, *s, ps, loc)) < 0) {
161 *src = s;
162 return ((size_t)-1);
163 }