]> git.saurik.com Git - apple/libc.git/blob - locale/FreeBSD/utf8.c.patch
9427108d2b4de627472bb4135254580dd8eca582
[apple/libc.git] / locale / FreeBSD / utf8.c.patch
1 --- utf8.c.bsdnew 2009-11-09 15:05:25.000000000 -0800
2 +++ utf8.c 2009-11-09 17:35:23.000000000 -0800
3 @@ -27,6 +27,8 @@
4 #include <sys/param.h>
5 __FBSDID("$FreeBSD: src/lib/libc/locale/utf8.c,v 1.16 2007/10/15 09:51:30 ache Exp $");
6
7 +#include "xlocale_private.h"
8 +
9 #include <errno.h>
10 #include <limits.h>
11 #include <runetype.h>
12 @@ -35,18 +37,18 @@ __FBSDID("$FreeBSD: src/lib/libc/locale/
13 #include <wchar.h>
14 #include "mblocal.h"
15
16 -extern int __mb_sb_limit;
17 +#define UTF8_MB_CUR_MAX 6
18
19 static size_t _UTF8_mbrtowc(wchar_t * __restrict, const char * __restrict,
20 - size_t, mbstate_t * __restrict);
21 -static int _UTF8_mbsinit(const mbstate_t *);
22 + size_t, mbstate_t * __restrict, locale_t);
23 +static int _UTF8_mbsinit(const mbstate_t *, locale_t);
24 static size_t _UTF8_mbsnrtowcs(wchar_t * __restrict,
25 const char ** __restrict, size_t, size_t,
26 - mbstate_t * __restrict);
27 + mbstate_t * __restrict, locale_t);
28 static size_t _UTF8_wcrtomb(char * __restrict, wchar_t,
29 - mbstate_t * __restrict);
30 + mbstate_t * __restrict, locale_t);
31 static size_t _UTF8_wcsnrtombs(char * __restrict, const wchar_t ** __restrict,
32 - size_t, size_t, mbstate_t * __restrict);
33 + size_t, size_t, mbstate_t * __restrict, locale_t);
34
35 typedef struct {
36 wchar_t ch;
37 @@ -54,29 +56,28 @@ typedef struct {
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 * UCS-4 encoding used as the internal representation, so
62 * slots 0x0080-0x00FF are occuped and must be excluded
63 * from the single byte ctype by setting the limit.
64 */
65 - __mb_sb_limit = 128;
66 + xrl->__mb_sb_limit = 128;
67
68 return (0);
69 }
70
71 static int
72 -_UTF8_mbsinit(const mbstate_t *ps)
73 +_UTF8_mbsinit(const mbstate_t *ps, locale_t loc)
74 {
75
76 return (ps == NULL || ((const _UTF8State *)ps)->want == 0);
77 @@ -84,7 +85,7 @@ _UTF8_mbsinit(const mbstate_t *ps)
78
79 static size_t
80 _UTF8_mbrtowc(wchar_t * __restrict pwc, const char * __restrict s, size_t n,
81 - mbstate_t * __restrict ps)
82 + mbstate_t * __restrict ps, locale_t loc)
83 {
84 _UTF8State *us;
85 int ch, i, mask, want;
86 @@ -206,7 +207,7 @@ _UTF8_mbrtowc(wchar_t * __restrict pwc,
87
88 static size_t
89 _UTF8_mbsnrtowcs(wchar_t * __restrict dst, const char ** __restrict src,
90 - size_t nms, size_t len, mbstate_t * __restrict ps)
91 + size_t nms, size_t len, mbstate_t * __restrict ps, locale_t loc)
92 {
93 _UTF8State *us;
94 const char *s;
95 @@ -236,7 +237,7 @@ _UTF8_mbsnrtowcs(wchar_t * __restrict ds
96 * excluding NUL.
97 */
98 nb = 1;
99 - else if ((nb = _UTF8_mbrtowc(&wc, s, nms, ps)) ==
100 + else if ((nb = _UTF8_mbrtowc(&wc, s, nms, ps, loc)) ==
101 (size_t)-1)
102 /* Invalid sequence - mbrtowc() sets errno. */
103 return ((size_t)-1);
104 @@ -266,7 +267,7 @@ _UTF8_mbsnrtowcs(wchar_t * __restrict ds
105 */
106 *dst = (wchar_t)*s;
107 nb = 1;
108 - } else if ((nb = _UTF8_mbrtowc(dst, s, nms, ps)) ==
109 + } else if ((nb = _UTF8_mbrtowc(dst, s, nms, ps, loc)) ==
110 (size_t)-1) {
111 *src = s;
112 return ((size_t)-1);
113 @@ -287,7 +288,7 @@ _UTF8_mbsnrtowcs(wchar_t * __restrict ds
114 }
115
116 static size_t
117 -_UTF8_wcrtomb(char * __restrict s, wchar_t wc, mbstate_t * __restrict ps)
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 @@ -356,7 +357,7 @@ _UTF8_wcrtomb(char * __restrict s, wchar
123
124 static size_t
125 _UTF8_wcsnrtombs(char * __restrict dst, const wchar_t ** __restrict src,
126 - size_t nwc, size_t len, mbstate_t * __restrict ps)
127 + size_t nwc, size_t len, mbstate_t * __restrict ps, locale_t loc)
128 {
129 _UTF8State *us;
130 char buf[MB_LEN_MAX];
131 @@ -379,7 +380,7 @@ _UTF8_wcsnrtombs(char * __restrict dst,
132 if (0 <= *s && *s < 0x80)
133 /* Fast path for plain ASCII characters. */
134 nb = 1;
135 - else if ((nb = _UTF8_wcrtomb(buf, *s, ps)) ==
136 + else if ((nb = _UTF8_wcrtomb(buf, *s, ps, loc)) ==
137 (size_t)-1)
138 /* Invalid character - wcrtomb() sets errno. */
139 return ((size_t)-1);
140 @@ -396,9 +397,9 @@ _UTF8_wcsnrtombs(char * __restrict dst,
141 /* Fast path for plain ASCII characters. */
142 nb = 1;
143 *dst = *s;
144 - } else if (len > (size_t)MB_CUR_MAX) {
145 + } else if (len > (size_t)UTF8_MB_CUR_MAX) {
146 /* Enough space to translate in-place. */
147 - if ((nb = _UTF8_wcrtomb(dst, *s, ps)) == (size_t)-1) {
148 + if ((nb = _UTF8_wcrtomb(dst, *s, ps, loc)) == (size_t)-1) {
149 *src = s;
150 return ((size_t)-1);
151 }
152 @@ -406,7 +407,7 @@ _UTF8_wcsnrtombs(char * __restrict dst,
153 /*
154 * May not be enough space; use temp. buffer.
155 */
156 - if ((nb = _UTF8_wcrtomb(buf, *s, ps)) == (size_t)-1) {
157 + if ((nb = _UTF8_wcrtomb(buf, *s, ps, loc)) == (size_t)-1) {
158 *src = s;
159 return ((size_t)-1);
160 }