Print this page
2964 need POSIX 2008 locale object support
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/lib/libc/port/locale/none.c
+++ new/usr/src/lib/libc/port/locale/none.c
1 1 /*
2 2 * Copyright 2010 Nexenta Systems, Inc. All rights reserved.
3 3 * Copyright (c) 2002-2004 Tim J. Robbins. All rights reserved.
4 4 * Copyright (c) 1993
5 5 * The Regents of the University of California. All rights reserved.
6 6 *
7 7 * This code is derived from software contributed to Berkeley by
8 8 * Paul Borman at Krystal Technologies.
9 9 *
10 + * Copyright (c) 2011 The FreeBSD Foundation
11 + * All rights reserved.
12 + * Portions of this software were developed by David Chisnall
13 + * under sponsorship from the FreeBSD Foundation.
14 + *
10 15 * Redistribution and use in source and binary forms, with or without
11 16 * modification, are permitted provided that the following conditions
12 17 * are met:
13 18 * 1. Redistributions of source code must retain the above copyright
14 19 * notice, this list of conditions and the following disclaimer.
15 20 * 2. Redistributions in binary form must reproduce the above copyright
16 21 * notice, this list of conditions and the following disclaimer in the
17 22 * documentation and/or other materials provided with the distribution.
18 23 * 4. Neither the name of the University nor the names of its contributors
19 24 * may be used to endorse or promote products derived from this software
20 25 * without specific prior written permission.
21 26 *
22 27 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 28 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 29 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 30 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 31 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 32 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 33 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 34 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 35 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 36 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 37 * SUCH DAMAGE.
33 38 */
34 39
35 40 #include "lint.h"
36 41 #include <errno.h>
37 42 #include <limits.h>
38 43 #include <stddef.h>
39 44 #include <stdio.h>
40 45 #include <stdlib.h>
41 46 #include <string.h>
42 47 #include <wchar.h>
43 48 #include <note.h>
44 49 #include "runetype.h"
45 50 #include "mblocal.h"
46 51
47 52 static size_t _none_mbrtowc(wchar_t *_RESTRICT_KYWD,
48 53 const char *_RESTRICT_KYWD, size_t, mbstate_t *_RESTRICT_KYWD);
49 54
50 55 static int _none_mbsinit(const mbstate_t *);
51 56 static size_t _none_mbsnrtowcs(wchar_t *_RESTRICT_KYWD dst,
52 57 const char **_RESTRICT_KYWD src, size_t nms, size_t len,
53 58 mbstate_t *_RESTRICT_KYWD);
54 59 static size_t _none_wcrtomb(char *_RESTRICT_KYWD, wchar_t,
55 60 mbstate_t *_RESTRICT_KYWD);
56 61 static size_t _none_wcsnrtombs(char *_RESTRICT_KYWD,
57 62 const wchar_t **_RESTRICT_KYWD,
58 63 size_t, size_t, mbstate_t *_RESTRICT_KYWD);
59 64
60 65 /* setup defaults */
61 66
62 67 int
63 68 _none_init(_RuneLocale *rl)
64 69 {
65 70 charset_is_ascii = 1;
66 71
67 72 __mbrtowc = _none_mbrtowc;
68 73 __mbsinit = _none_mbsinit;
69 74 __mbsnrtowcs = _none_mbsnrtowcs;
70 75 __wcrtomb = _none_wcrtomb;
71 76 __wcsnrtombs = _none_wcsnrtombs;
72 77 _CurrentRuneLocale = rl;
73 78 return (0);
74 79 }
75 80
76 81 static int
77 82 _none_mbsinit(const mbstate_t *unused)
78 83 {
79 84 _NOTE(ARGUNUSED(unused));
80 85
81 86 /*
82 87 * Encoding is not state dependent - we are always in the
83 88 * initial state.
84 89 */
85 90 return (1);
86 91 }
87 92
88 93 static size_t
89 94 _none_mbrtowc(wchar_t *_RESTRICT_KYWD pwc, const char *_RESTRICT_KYWD s,
90 95 size_t n, mbstate_t *_RESTRICT_KYWD unused)
91 96 {
92 97 _NOTE(ARGUNUSED(unused));
93 98
94 99 if (s == NULL)
95 100 /* Reset to initial shift state (no-op) */
96 101 return (0);
97 102 if (n == 0)
98 103 /* Incomplete multibyte sequence */
99 104 return ((size_t)-2);
100 105 if (pwc != NULL)
101 106 *pwc = (unsigned char)*s;
102 107 return (*s == '\0' ? 0 : 1);
103 108 }
104 109
105 110 static size_t
106 111 _none_wcrtomb(char *_RESTRICT_KYWD s, wchar_t wc,
107 112 mbstate_t *_RESTRICT_KYWD unused)
108 113 {
109 114 _NOTE(ARGUNUSED(unused));
110 115
111 116 if (s == NULL)
112 117 /* Reset to initial shift state (no-op) */
113 118 return (1);
114 119 if (wc < 0 || wc > UCHAR_MAX) {
115 120 errno = EILSEQ;
116 121 return ((size_t)-1);
117 122 }
118 123 *s = (unsigned char)wc;
119 124 return (1);
120 125 }
121 126
122 127 static size_t
123 128 _none_mbsnrtowcs(wchar_t *_RESTRICT_KYWD dst, const char **_RESTRICT_KYWD src,
124 129 size_t nms, size_t len, mbstate_t *_RESTRICT_KYWD unused)
125 130 {
126 131 const char *s;
127 132 size_t nchr;
128 133
129 134 _NOTE(ARGUNUSED(unused));
130 135
131 136 if (dst == NULL) {
132 137 s = memchr(*src, '\0', nms);
133 138 return (s != NULL ? s - *src : nms);
134 139 }
135 140
136 141 s = *src;
137 142 nchr = 0;
138 143 while (len-- > 0 && nms-- > 0) {
139 144 if ((*dst++ = (unsigned char)*s++) == L'\0') {
140 145 *src = NULL;
141 146 return (nchr);
142 147 }
143 148 nchr++;
144 149 }
145 150 *src = s;
146 151 return (nchr);
147 152 }
148 153
149 154 static size_t
150 155 _none_wcsnrtombs(char *_RESTRICT_KYWD dst, const wchar_t **_RESTRICT_KYWD src,
151 156 size_t nwc, size_t len, mbstate_t *_RESTRICT_KYWD unused)
152 157 {
153 158 const wchar_t *s;
154 159 size_t nchr;
155 160
156 161 _NOTE(ARGUNUSED(unused));
157 162
158 163 if (dst == NULL) {
159 164 for (s = *src; nwc > 0 && *s != L'\0'; s++, nwc--) {
160 165 if (*s < 0 || *s > UCHAR_MAX) {
161 166 errno = EILSEQ;
162 167 return ((size_t)-1);
163 168 }
164 169 }
165 170 return (s - *src);
166 171 }
167 172
168 173 s = *src;
169 174 nchr = 0;
170 175 while (len-- > 0 && nwc-- > 0) {
171 176 if (*s < 0 || *s > UCHAR_MAX) {
172 177 errno = EILSEQ;
173 178 return ((size_t)-1);
174 179 }
175 180 if ((*dst++ = *s++) == '\0') {
176 181 *src = NULL;
177 182 return (nchr);
178 183 }
179 184 nchr++;
180 185 }
181 186 *src = s;
182 187 return (nchr);
183 188 }
184 189
185 190 /* setup defaults */
186 191
187 192 size_t (*__mbrtowc)(wchar_t *_RESTRICT_KYWD, const char *_RESTRICT_KYWD,
188 193 size_t, mbstate_t *_RESTRICT_KYWD) = _none_mbrtowc;
189 194
↓ open down ↓ |
170 lines elided |
↑ open up ↑ |
190 195 int (*__mbsinit)(const mbstate_t *) = _none_mbsinit;
191 196
192 197 size_t (*__mbsnrtowcs)(wchar_t *_RESTRICT_KYWD, const char **_RESTRICT_KYWD,
193 198 size_t, size_t, mbstate_t *_RESTRICT_KYWD) = _none_mbsnrtowcs;
194 199
195 200 size_t (*__wcrtomb)(char *_RESTRICT_KYWD, wchar_t, mbstate_t *_RESTRICT_KYWD) =
196 201 _none_wcrtomb;
197 202
198 203 size_t (*__wcsnrtombs)(char *_RESTRICT_KYWD, const wchar_t **_RESTRICT_KYWD,
199 204 size_t, size_t, mbstate_t *_RESTRICT_KYWD) = _none_wcsnrtombs;
205 +
206 +struct xlocale_ctype __xlocale_global_ctype = {
207 + {{0}, "C"},
208 + (_RuneLocale*)&_DefaultRuneLocale,
209 + _none_mbrtowc,
210 + _none_mbsinit,
211 + _none_mbsnrtowcs,
212 + _none_wcrtomb,
213 + _none_wcsnrtombs,
214 + 1, /* __mb_cur_max */
215 + 256 /* __mb_sb_limit */
216 +};
217 +
218 +const struct xlocale_ctype __xlocale_C_ctype = {
219 + {{0}, "C"},
220 + (_RuneLocale*)&_DefaultRuneLocale,
221 + _none_mbrtowc,
222 + _none_mbsinit,
223 + _none_mbsnrtowcs,
224 + _none_wcrtomb,
225 + _none_wcsnrtombs,
226 + 1, /* __mb_cur_max */
227 + 256 /* __mb_sb_limit */
228 +};
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX