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