1 /* $FreeBSD: head/lib/libc/iconv/citrus_none.c 281550 2015-04-15 09:09:20Z tijl $ */
2 /* $NetBSD: citrus_none.c,v 1.18 2008/06/14 16:01:07 tnozaki Exp $ */
5 * Copyright (c) 2002 Citrus Project,
6 * Copyright (c) 2010 Gabor Kovesdan <gabor@FreeBSD.org>,
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 #include <sys/cdefs.h>
32 #include <sys/types.h>
43 #include "citrus_namespace.h"
44 #include "citrus_types.h"
45 #include "citrus_module.h"
46 #include "citrus_none.h"
47 #include "citrus_stdenc.h"
49 _CITRUS_STDENC_DECLS(NONE
);
50 _CITRUS_STDENC_DEF_OPS(NONE
);
51 struct _citrus_stdenc_traits _citrus_NONE_stdenc_traits
= {
52 0, /* et_state_size */
57 _citrus_NONE_stdenc_init(struct _citrus_stdenc
* __restrict ce
,
58 const void *var __unused
, size_t lenvar __unused
,
59 struct _citrus_stdenc_traits
* __restrict et
)
62 et
->et_state_size
= 0;
63 et
->et_mb_cur_max
= 1;
65 ce
->ce_closure
= NULL
;
71 _citrus_NONE_stdenc_uninit(struct _citrus_stdenc
*ce __unused
)
77 _citrus_NONE_stdenc_init_state(struct _citrus_stdenc
* __restrict ce __unused
,
78 void * __restrict ps __unused
)
85 _citrus_NONE_stdenc_mbtocs(struct _citrus_stdenc
* __restrict ce __unused
,
86 _csid_t
*csid
, _index_t
*idx
, char **s
, size_t n
,
87 void *ps __unused
, size_t *nresult
, struct iconv_hooks
*hooks
)
91 *nresult
= (size_t)-2;
96 *idx
= (_index_t
)(unsigned char)*(*s
)++;
97 *nresult
= *idx
== 0 ? 0 : 1;
99 if ((hooks
!= NULL
) && (hooks
->uc_hook
!= NULL
))
100 hooks
->uc_hook((unsigned int)*idx
, hooks
->data
);
106 _citrus_NONE_stdenc_cstomb(struct _citrus_stdenc
* __restrict ce __unused
,
107 char *s
, size_t n
, _csid_t csid
, _index_t idx
, void *ps __unused
,
108 size_t *nresult
, struct iconv_hooks
*hooks __unused
)
111 if (csid
== _CITRUS_CSID_INVALID
) {
118 if ((idx
& 0x000000FF) == idx
) {
120 *nresult
= (size_t)-1;
125 } else if ((idx
& 0x0000FFFF) == idx
) {
127 *nresult
= (size_t)-1;
131 /* XXX: might be endian dependent */
132 s
[1] = (char)(idx
>> 8);
134 } else if ((idx
& 0x00FFFFFF) == idx
) {
136 *nresult
= (size_t)-1;
140 /* XXX: might be endian dependent */
141 s
[1] = (char)(idx
>> 8);
142 s
[2] = (char)(idx
>> 16);
146 *nresult
= (size_t)-1;
150 /* XXX: might be endian dependent */
151 s
[1] = (char)(idx
>> 8);
152 s
[2] = (char)(idx
>> 16);
153 s
[3] = (char)(idx
>> 24);
161 _citrus_NONE_stdenc_mbtowc(struct _citrus_stdenc
* __restrict ce __unused
,
162 _wc_t
* __restrict pwc
, char ** __restrict s
, size_t n
,
163 void * __restrict pspriv __unused
, size_t * __restrict nresult
,
164 struct iconv_hooks
*hooks
)
166 _DIAGASSERT(s
!= NULL
);
173 *nresult
= (size_t)-2;
178 *pwc
= (_wc_t
)(unsigned char) **s
;
180 *nresult
= **s
== '\0' ? 0 : 1;
182 if ((hooks
!= NULL
) && (hooks
->wc_hook
!= NULL
))
183 hooks
->wc_hook(*pwc
, hooks
->data
);
189 _citrus_NONE_stdenc_wctomb(struct _citrus_stdenc
* __restrict ce __unused
,
190 char * __restrict s
, size_t n
, _wc_t wc
,
191 void * __restrict pspriv __unused
, size_t * __restrict nresult
,
192 struct iconv_hooks
*hooks __unused
)
195 if ((wc
& ~0xFFU
) != 0) {
196 *nresult
= (size_t)-1;
200 *nresult
= (size_t)-1;
205 if (s
!= NULL
&& n
> 0)
212 _citrus_NONE_stdenc_put_state_reset(struct _citrus_stdenc
* __restrict ce __unused
,
213 char * __restrict s __unused
, size_t n __unused
,
214 void * __restrict pspriv __unused
, size_t * __restrict nresult
)
223 _citrus_NONE_stdenc_get_state_desc(struct _stdenc
* __restrict ce __unused
,
224 void * __restrict ps __unused
, int id
,
225 struct _stdenc_state_desc
* __restrict d
)
230 case _STDENC_SDID_GENERIC
:
231 d
->u
.generic
.state
= _STDENC_SDGEN_INITIAL
;