1 --- utf8.c.bsdnew 2009-11-09 15:05:25.000000000 -0800
2 +++ utf8.c 2009-11-09 17:35:23.000000000 -0800
5 __FBSDID("$FreeBSD: src/lib/libc/locale/utf8.c,v 1.16 2007/10/15 09:51:30 ache Exp $");
7 +#include "xlocale_private.h"
12 @@ -35,18 +37,18 @@ __FBSDID("$FreeBSD: src/lib/libc/locale/
16 -extern int __mb_sb_limit;
17 +#define UTF8_MB_CUR_MAX 6
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);
37 @@ -54,29 +56,28 @@ typedef struct {
42 -_UTF8_init(_RuneLocale *rl)
43 +__private_extern__ int
44 +_UTF8_init(struct __xlocale_st_runelocale *xrl)
47 - __mbrtowc = _UTF8_mbrtowc;
48 - __wcrtomb = _UTF8_wcrtomb;
49 - __mbsinit = _UTF8_mbsinit;
50 - __mbsnrtowcs = _UTF8_mbsnrtowcs;
51 - __wcsnrtombs = _UTF8_wcsnrtombs;
52 - _CurrentRuneLocale = rl;
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;
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.
65 - __mb_sb_limit = 128;
66 + xrl->__mb_sb_limit = 128;
72 -_UTF8_mbsinit(const mbstate_t *ps)
73 +_UTF8_mbsinit(const mbstate_t *ps, locale_t loc)
76 return (ps == NULL || ((const _UTF8State *)ps)->want == 0);
77 @@ -84,7 +85,7 @@ _UTF8_mbsinit(const mbstate_t *ps)
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)
85 int ch, i, mask, want;
86 @@ -206,7 +207,7 @@ _UTF8_mbrtowc(wchar_t * __restrict pwc,
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)
95 @@ -236,7 +237,7 @@ _UTF8_mbsnrtowcs(wchar_t * __restrict ds
99 - else if ((nb = _UTF8_mbrtowc(&wc, s, nms, ps)) ==
100 + else if ((nb = _UTF8_mbrtowc(&wc, s, nms, ps, loc)) ==
102 /* Invalid sequence - mbrtowc() sets errno. */
104 @@ -266,7 +267,7 @@ _UTF8_mbsnrtowcs(wchar_t * __restrict ds
108 - } else if ((nb = _UTF8_mbrtowc(dst, s, nms, ps)) ==
109 + } else if ((nb = _UTF8_mbrtowc(dst, s, nms, ps, loc)) ==
113 @@ -287,7 +288,7 @@ _UTF8_mbsnrtowcs(wchar_t * __restrict ds
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)
122 @@ -356,7 +357,7 @@ _UTF8_wcrtomb(char * __restrict s, wchar
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)
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. */
135 - else if ((nb = _UTF8_wcrtomb(buf, *s, ps)) ==
136 + else if ((nb = _UTF8_wcrtomb(buf, *s, ps, loc)) ==
138 /* Invalid character - wcrtomb() sets errno. */
140 @@ -396,9 +397,9 @@ _UTF8_wcsnrtombs(char * __restrict dst,
141 /* Fast path for plain ASCII characters. */
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) {
152 @@ -406,7 +407,7 @@ _UTF8_wcsnrtombs(char * __restrict dst,
154 * May not be enough space; use temp. buffer.
156 - if ((nb = _UTF8_wcrtomb(buf, *s, ps)) == (size_t)-1) {
157 + if ((nb = _UTF8_wcrtomb(buf, *s, ps, loc)) == (size_t)-1) {