1 --- utf8.c.orig Thu Nov 25 11:38:20 2004
2 +++ utf8.c Fri Feb 18 15:40:44 2005
5 __FBSDID("$FreeBSD: src/lib/libc/locale/utf8.c,v 1.11 2004/07/27 06:29:48 tjr Exp $");
7 +#include "xlocale_private.h"
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
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);
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;
65 -_UTF8_mbsinit(const mbstate_t *ps)
67 +_UTF8_mbsinit(const mbstate_t *ps, locale_t loc)
70 return (ps == NULL || ((const _UTF8State *)ps)->want == 0);
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)
80 int ch, i, mask, want;
82 return (wch == L'\0' ? 0 : want);
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)
97 - else if ((nb = _UTF8_mbrtowc(&wc, s, nms, ps)) ==
98 + else if ((nb = _UTF8_mbrtowc(&wc, s, nms, ps, loc)) ==
100 /* Invalid sequence - mbrtowc() sets errno. */
106 - } else if ((nb = _UTF8_mbrtowc(dst, s, nms, ps)) ==
107 + } else if ((nb = _UTF8_mbrtowc(dst, s, nms, ps, loc)) ==
116 -_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)
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)
133 char buf[MB_LEN_MAX];
135 if (0 <= *s && *s < 0x80)
136 /* Fast path for plain ASCII characters. */
138 - else if ((nb = _UTF8_wcrtomb(buf, *s, ps)) ==
139 + else if ((nb = _UTF8_wcrtomb(buf, *s, ps, loc)) ==
141 /* Invalid character - wcrtomb() sets errno. */
144 /* Fast path for plain ASCII characters. */
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) {
157 * May not be enough space; use temp. buffer.
159 - if ((nb = (int)_UTF8_wcrtomb(buf, *s, ps)) < 0) {
160 + if ((nb = (int)_UTF8_wcrtomb(buf, *s, ps, loc)) < 0) {