]>
Commit | Line | Data |
---|---|---|
3d9156a7 A |
1 | --- gb18030.c.orig Thu Nov 25 11:38:16 2004 |
2 | +++ gb18030.c Fri Feb 18 15:43:22 2005 | |
3 | @@ -32,6 +32,8 @@ | |
4 | #include <sys/param.h> | |
5 | __FBSDID("$FreeBSD: src/lib/libc/locale/gb18030.c,v 1.6 2004/05/12 14:09:04 tjr Exp $"); | |
6 | ||
7 | +#include "xlocale_private.h" | |
8 | + | |
9 | #include <errno.h> | |
10 | #include <runetype.h> | |
11 | #include <stdlib.h> | |
12 | @@ -39,40 +41,41 @@ | |
13 | #include <wchar.h> | |
14 | #include "mblocal.h" | |
15 | ||
16 | -int _GB18030_init(_RuneLocale *); | |
17 | -size_t _GB18030_mbrtowc(wchar_t * __restrict, const char * __restrict, size_t, | |
18 | - mbstate_t * __restrict); | |
19 | -int _GB18030_mbsinit(const mbstate_t *); | |
20 | -size_t _GB18030_wcrtomb(char * __restrict, wchar_t, mbstate_t * __restrict); | |
21 | +#define GB18030_MB_CUR_MAX 4 | |
22 | + | |
23 | +__private_extern__ int _GB18030_init(struct __xlocale_st_runelocale *); | |
24 | +static size_t _GB18030_mbrtowc(wchar_t * __restrict, const char * __restrict, size_t, | |
25 | + mbstate_t * __restrict, locale_t); | |
26 | +static int _GB18030_mbsinit(const mbstate_t *, locale_t); | |
27 | +static size_t _GB18030_wcrtomb(char * __restrict, wchar_t, mbstate_t * __restrict, locale_t); | |
28 | ||
29 | typedef struct { | |
30 | int count; | |
31 | u_char bytes[4]; | |
32 | } _GB18030State; | |
33 | ||
34 | -int | |
35 | -_GB18030_init(_RuneLocale *rl) | |
36 | +__private_extern__ int | |
37 | +_GB18030_init(struct __xlocale_st_runelocale *xrl) | |
38 | { | |
39 | ||
40 | - __mbrtowc = _GB18030_mbrtowc; | |
41 | - __wcrtomb = _GB18030_wcrtomb; | |
42 | - __mbsinit = _GB18030_mbsinit; | |
43 | - _CurrentRuneLocale = rl; | |
44 | - __mb_cur_max = 4; | |
45 | + xrl->__mbrtowc = _GB18030_mbrtowc; | |
46 | + xrl->__wcrtomb = _GB18030_wcrtomb; | |
47 | + xrl->__mbsinit = _GB18030_mbsinit; | |
48 | + xrl->__mb_cur_max = GB18030_MB_CUR_MAX; | |
49 | ||
50 | return (0); | |
51 | } | |
52 | ||
53 | -int | |
54 | -_GB18030_mbsinit(const mbstate_t *ps) | |
55 | +static int | |
56 | +_GB18030_mbsinit(const mbstate_t *ps, locale_t loc) | |
57 | { | |
58 | ||
59 | return (ps == NULL || ((const _GB18030State *)ps)->count == 0); | |
60 | } | |
61 | ||
62 | -size_t | |
63 | +static size_t | |
64 | _GB18030_mbrtowc(wchar_t * __restrict pwc, const char * __restrict s, | |
65 | - size_t n, mbstate_t * __restrict ps) | |
66 | + size_t n, mbstate_t * __restrict ps, locale_t loc) | |
67 | { | |
68 | _GB18030State *gs; | |
69 | wchar_t wch; | |
70 | @@ -92,7 +95,7 @@ | |
71 | pwc = NULL; | |
72 | } | |
73 | ||
74 | - ncopy = MIN(MIN(n, MB_CUR_MAX), sizeof(gs->bytes) - gs->count); | |
75 | + ncopy = MIN(MIN(n, GB18030_MB_CUR_MAX), sizeof(gs->bytes) - gs->count); | |
76 | memcpy(gs->bytes + gs->count, s, ncopy); | |
77 | ocount = gs->count; | |
78 | gs->count += ncopy; | |
79 | @@ -154,8 +157,8 @@ | |
80 | return ((size_t)-1); | |
81 | } | |
82 | ||
83 | -size_t | |
84 | -_GB18030_wcrtomb(char * __restrict s, wchar_t wc, mbstate_t * __restrict ps) | |
85 | +static size_t | |
86 | +_GB18030_wcrtomb(char * __restrict s, wchar_t wc, mbstate_t * __restrict ps, locale_t loc) | |
87 | { | |
88 | _GB18030State *gs; | |
89 | size_t len; |