2 * Copyright 2013 Garrett D'Amore <garrett@damore.org>
3 * Copyright 2010 Nexenta Systems, Inc. All rights reserved.
4 * Copyright (c) 2002-2004 Tim J. Robbins. All rights reserved.
6 * The Regents of the University of California. All rights reserved.
8 * This code is derived from software contributed to Berkeley by
9 * Paul Borman at Krystal Technologies.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 4. Neither the name of the University nor the names of its contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 _none_init(struct lc_ctype
*lct
)
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;
63 __mbsinit_ascii(const mbstate_t *unused
)
65 _NOTE(ARGUNUSED(unused
));
68 * Encoding is not state dependent - we are always in the
75 __mbrtowc_ascii(wchar_t *_RESTRICT_KYWD pwc
, const char *_RESTRICT_KYWD s
,
76 size_t n
, mbstate_t *_RESTRICT_KYWD unused
)
78 _NOTE(ARGUNUSED(unused
));
81 /* Reset to initial shift state (no-op) */
84 /* Incomplete multibyte sequence */
87 *pwc
= (unsigned char)*s
;
88 return (*s
== '\0' ? 0 : 1);
92 __wcrtomb_ascii(char *_RESTRICT_KYWD s
, wchar_t wc
,
93 mbstate_t *_RESTRICT_KYWD unused
)
95 _NOTE(ARGUNUSED(unused
));
98 /* Reset to initial shift state (no-op) */
100 if (wc
< 0 || wc
> UCHAR_MAX
) {
104 *s
= (unsigned char)wc
;
109 __mbsnrtowcs_ascii(wchar_t *_RESTRICT_KYWD dst
, const char **_RESTRICT_KYWD src
,
110 size_t nms
, size_t len
, mbstate_t *_RESTRICT_KYWD unused
)
115 _NOTE(ARGUNUSED(unused
));
118 s
= memchr(*src
, '\0', nms
);
119 return (s
!= NULL
? s
- *src
: nms
);
124 while (len
-- > 0 && nms
-- > 0) {
125 if ((*dst
++ = (unsigned char)*s
++) == L
'\0') {
136 __wcsnrtombs_ascii(char *_RESTRICT_KYWD dst
, const wchar_t **_RESTRICT_KYWD src
,
137 size_t nwc
, size_t len
, mbstate_t *_RESTRICT_KYWD unused
)
142 _NOTE(ARGUNUSED(unused
));
145 for (s
= *src
; nwc
> 0 && *s
!= L
'\0'; s
++, nwc
--) {
146 if (*s
< 0 || *s
> UCHAR_MAX
) {
156 while (len
-- > 0 && nwc
-- > 0) {
157 if (*s
< 0 || *s
> UCHAR_MAX
) {
161 if ((*dst
++ = *s
++) == '\0') {