1ad30f8e7SGabor Kovesdan /* $FreeBSD$ */ 2ad30f8e7SGabor Kovesdan /* $NetBSD: citrus_utf8.c,v 1.17 2008/06/14 16:01:08 tnozaki Exp $ */ 3ad30f8e7SGabor Kovesdan 4ad30f8e7SGabor Kovesdan /*- 5ad30f8e7SGabor Kovesdan * Copyright (c)2002 Citrus Project, 6ad30f8e7SGabor Kovesdan * All rights reserved. 7ad30f8e7SGabor Kovesdan * 8ad30f8e7SGabor Kovesdan * Redistribution and use in source and binary forms, with or without 9ad30f8e7SGabor Kovesdan * modification, are permitted provided that the following conditions 10ad30f8e7SGabor Kovesdan * are met: 11ad30f8e7SGabor Kovesdan * 1. Redistributions of source code must retain the above copyright 12ad30f8e7SGabor Kovesdan * notice, this list of conditions and the following disclaimer. 13ad30f8e7SGabor Kovesdan * 2. Redistributions in binary form must reproduce the above copyright 14ad30f8e7SGabor Kovesdan * notice, this list of conditions and the following disclaimer in the 15ad30f8e7SGabor Kovesdan * documentation and/or other materials provided with the distribution. 16ad30f8e7SGabor Kovesdan * 17ad30f8e7SGabor Kovesdan * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 18ad30f8e7SGabor Kovesdan * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19ad30f8e7SGabor Kovesdan * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20ad30f8e7SGabor Kovesdan * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 21ad30f8e7SGabor Kovesdan * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22ad30f8e7SGabor Kovesdan * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23ad30f8e7SGabor Kovesdan * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24ad30f8e7SGabor Kovesdan * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25ad30f8e7SGabor Kovesdan * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26ad30f8e7SGabor Kovesdan * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27ad30f8e7SGabor Kovesdan * SUCH DAMAGE. 28ad30f8e7SGabor Kovesdan */ 29ad30f8e7SGabor Kovesdan 30ad30f8e7SGabor Kovesdan /*- 31*8a16b7a1SPedro F. Giffuni * SPDX-License-Identifier: BSD-3-Clause 32*8a16b7a1SPedro F. Giffuni * 33ad30f8e7SGabor Kovesdan * Copyright (c) 1993 34ad30f8e7SGabor Kovesdan * The Regents of the University of California. All rights reserved. 35ad30f8e7SGabor Kovesdan * 36ad30f8e7SGabor Kovesdan * This code is derived from software contributed to Berkeley by 37ad30f8e7SGabor Kovesdan * Paul Borman at Krystal Technologies. 38ad30f8e7SGabor Kovesdan * 39ad30f8e7SGabor Kovesdan * Redistribution and use in source and binary forms, with or without 40ad30f8e7SGabor Kovesdan * modification, are permitted provided that the following conditions 41ad30f8e7SGabor Kovesdan * are met: 42ad30f8e7SGabor Kovesdan * 1. Redistributions of source code must retain the above copyright 43ad30f8e7SGabor Kovesdan * notice, this list of conditions and the following disclaimer. 44ad30f8e7SGabor Kovesdan * 2. Redistributions in binary form must reproduce the above copyright 45ad30f8e7SGabor Kovesdan * notice, this list of conditions and the following disclaimer in the 46ad30f8e7SGabor Kovesdan * documentation and/or other materials provided with the distribution. 47ad30f8e7SGabor Kovesdan * 3. Neither the name of the University nor the names of its contributors 48ad30f8e7SGabor Kovesdan * may be used to endorse or promote products derived from this software 49ad30f8e7SGabor Kovesdan * without specific prior written permission. 50ad30f8e7SGabor Kovesdan * 51ad30f8e7SGabor Kovesdan * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 52ad30f8e7SGabor Kovesdan * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 53ad30f8e7SGabor Kovesdan * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 54ad30f8e7SGabor Kovesdan * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 55ad30f8e7SGabor Kovesdan * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 56ad30f8e7SGabor Kovesdan * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 57ad30f8e7SGabor Kovesdan * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 58ad30f8e7SGabor Kovesdan * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 59ad30f8e7SGabor Kovesdan * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 60ad30f8e7SGabor Kovesdan * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 61ad30f8e7SGabor Kovesdan * SUCH DAMAGE. 62ad30f8e7SGabor Kovesdan */ 63ad30f8e7SGabor Kovesdan 64ad30f8e7SGabor Kovesdan #include <sys/cdefs.h> 65ad30f8e7SGabor Kovesdan #include <sys/types.h> 66ad30f8e7SGabor Kovesdan 67ad30f8e7SGabor Kovesdan #include <assert.h> 68ad30f8e7SGabor Kovesdan #include <errno.h> 69ad30f8e7SGabor Kovesdan #include <limits.h> 70ad30f8e7SGabor Kovesdan #include <stdbool.h> 71ad30f8e7SGabor Kovesdan #include <stddef.h> 72ad30f8e7SGabor Kovesdan #include <stdio.h> 73ad30f8e7SGabor Kovesdan #include <stdlib.h> 74ad30f8e7SGabor Kovesdan #include <string.h> 75ad30f8e7SGabor Kovesdan #include <wchar.h> 76ad30f8e7SGabor Kovesdan 77ad30f8e7SGabor Kovesdan #include "citrus_namespace.h" 78ad30f8e7SGabor Kovesdan #include "citrus_types.h" 79ad30f8e7SGabor Kovesdan #include "citrus_module.h" 80ad30f8e7SGabor Kovesdan #include "citrus_stdenc.h" 81ad30f8e7SGabor Kovesdan #include "citrus_utf8.h" 82ad30f8e7SGabor Kovesdan 83ad30f8e7SGabor Kovesdan 84ad30f8e7SGabor Kovesdan /* ---------------------------------------------------------------------- 85ad30f8e7SGabor Kovesdan * private stuffs used by templates 86ad30f8e7SGabor Kovesdan */ 87ad30f8e7SGabor Kovesdan 88ad30f8e7SGabor Kovesdan static uint8_t _UTF8_count_array[256] = { 89ad30f8e7SGabor Kovesdan 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 00 - 0F */ 90ad30f8e7SGabor Kovesdan 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 10 - 1F */ 91ad30f8e7SGabor Kovesdan 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 20 - 2F */ 92ad30f8e7SGabor Kovesdan 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 30 - 3F */ 93ad30f8e7SGabor Kovesdan 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 40 - 4F */ 94ad30f8e7SGabor Kovesdan 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 50 - 5F */ 95ad30f8e7SGabor Kovesdan 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 60 - 6F */ 96ad30f8e7SGabor Kovesdan 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 70 - 7F */ 97ad30f8e7SGabor Kovesdan 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 80 - 8F */ 98ad30f8e7SGabor Kovesdan 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 90 - 9F */ 99ad30f8e7SGabor Kovesdan 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* A0 - AF */ 100ad30f8e7SGabor Kovesdan 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* B0 - BF */ 101ad30f8e7SGabor Kovesdan 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, /* C0 - CF */ 102ad30f8e7SGabor Kovesdan 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, /* D0 - DF */ 103ad30f8e7SGabor Kovesdan 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, /* E0 - EF */ 104ad30f8e7SGabor Kovesdan 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 0, 0 /* F0 - FF */ 105ad30f8e7SGabor Kovesdan }; 106ad30f8e7SGabor Kovesdan 107ad30f8e7SGabor Kovesdan static uint8_t const *_UTF8_count = _UTF8_count_array; 108ad30f8e7SGabor Kovesdan 109ad30f8e7SGabor Kovesdan static const uint32_t _UTF8_range[] = { 110ad30f8e7SGabor Kovesdan 0, /*dummy*/ 111ad30f8e7SGabor Kovesdan 0x00000000, 0x00000080, 0x00000800, 0x00010000, 112ad30f8e7SGabor Kovesdan 0x00200000, 0x04000000, 0x80000000, 113ad30f8e7SGabor Kovesdan }; 114ad30f8e7SGabor Kovesdan 115ad30f8e7SGabor Kovesdan typedef struct { 116ad30f8e7SGabor Kovesdan int chlen; 117ad30f8e7SGabor Kovesdan char ch[6]; 118ad30f8e7SGabor Kovesdan } _UTF8State; 119ad30f8e7SGabor Kovesdan 120ad30f8e7SGabor Kovesdan typedef void *_UTF8EncodingInfo; 121ad30f8e7SGabor Kovesdan 122ad30f8e7SGabor Kovesdan #define _CEI_TO_EI(_cei_) (&(_cei_)->ei) 123ad30f8e7SGabor Kovesdan #define _CEI_TO_STATE(_ei_, _func_) (_ei_)->states.s_##_func_ 124ad30f8e7SGabor Kovesdan 125ad30f8e7SGabor Kovesdan #define _FUNCNAME(m) _citrus_UTF8_##m 126ad30f8e7SGabor Kovesdan #define _ENCODING_INFO _UTF8EncodingInfo 127ad30f8e7SGabor Kovesdan #define _ENCODING_STATE _UTF8State 128ad30f8e7SGabor Kovesdan #define _ENCODING_MB_CUR_MAX(_ei_) 6 129ad30f8e7SGabor Kovesdan #define _ENCODING_IS_STATE_DEPENDENT 0 130ad30f8e7SGabor Kovesdan #define _STATE_NEEDS_EXPLICIT_INIT(_ps_) 0 131ad30f8e7SGabor Kovesdan 132ad30f8e7SGabor Kovesdan static size_t 133ad30f8e7SGabor Kovesdan _UTF8_findlen(wchar_t v) 134ad30f8e7SGabor Kovesdan { 135ad30f8e7SGabor Kovesdan size_t i; 136ad30f8e7SGabor Kovesdan uint32_t c; 137ad30f8e7SGabor Kovesdan 138ad30f8e7SGabor Kovesdan c = (uint32_t)v; /*XXX*/ 139ad30f8e7SGabor Kovesdan for (i = 1; i < sizeof(_UTF8_range) / sizeof(_UTF8_range[0]) - 1; i++) 140ad30f8e7SGabor Kovesdan if (c >= _UTF8_range[i] && c < _UTF8_range[i + 1]) 141ad30f8e7SGabor Kovesdan return (i); 142ad30f8e7SGabor Kovesdan 143ad30f8e7SGabor Kovesdan return (-1); /*out of range*/ 144ad30f8e7SGabor Kovesdan } 145ad30f8e7SGabor Kovesdan 146ad30f8e7SGabor Kovesdan static __inline bool 147ad30f8e7SGabor Kovesdan _UTF8_surrogate(wchar_t wc) 148ad30f8e7SGabor Kovesdan { 149ad30f8e7SGabor Kovesdan 150ad30f8e7SGabor Kovesdan return (wc >= 0xd800 && wc <= 0xdfff); 151ad30f8e7SGabor Kovesdan } 152ad30f8e7SGabor Kovesdan 153ad30f8e7SGabor Kovesdan static __inline void 154ad30f8e7SGabor Kovesdan /*ARGSUSED*/ 155ad30f8e7SGabor Kovesdan _citrus_UTF8_init_state(_UTF8EncodingInfo *ei __unused, _UTF8State *s) 156ad30f8e7SGabor Kovesdan { 157ad30f8e7SGabor Kovesdan 158ad30f8e7SGabor Kovesdan s->chlen = 0; 159ad30f8e7SGabor Kovesdan } 160ad30f8e7SGabor Kovesdan 161b61949ddSDimitry Andric #if 0 162ad30f8e7SGabor Kovesdan static __inline void 163ad30f8e7SGabor Kovesdan /*ARGSUSED*/ 164ad30f8e7SGabor Kovesdan _citrus_UTF8_pack_state(_UTF8EncodingInfo *ei __unused, void *pspriv, 165ad30f8e7SGabor Kovesdan const _UTF8State *s) 166ad30f8e7SGabor Kovesdan { 167ad30f8e7SGabor Kovesdan 168ad30f8e7SGabor Kovesdan memcpy(pspriv, (const void *)s, sizeof(*s)); 169ad30f8e7SGabor Kovesdan } 170ad30f8e7SGabor Kovesdan 171ad30f8e7SGabor Kovesdan static __inline void 172ad30f8e7SGabor Kovesdan /*ARGSUSED*/ 173ad30f8e7SGabor Kovesdan _citrus_UTF8_unpack_state(_UTF8EncodingInfo *ei __unused, _UTF8State *s, 174ad30f8e7SGabor Kovesdan const void *pspriv) 175ad30f8e7SGabor Kovesdan { 176ad30f8e7SGabor Kovesdan 177ad30f8e7SGabor Kovesdan memcpy((void *)s, pspriv, sizeof(*s)); 178ad30f8e7SGabor Kovesdan } 179b61949ddSDimitry Andric #endif 180ad30f8e7SGabor Kovesdan 181ad30f8e7SGabor Kovesdan static int 1821243a98eSTijl Coosemans _citrus_UTF8_mbrtowc_priv(_UTF8EncodingInfo *ei, wchar_t *pwc, char **s, 183ad30f8e7SGabor Kovesdan size_t n, _UTF8State *psenc, size_t *nresult) 184ad30f8e7SGabor Kovesdan { 1851243a98eSTijl Coosemans char *s0; 186ad30f8e7SGabor Kovesdan wchar_t wchar; 187ad30f8e7SGabor Kovesdan int i; 188ad30f8e7SGabor Kovesdan uint8_t c; 189ad30f8e7SGabor Kovesdan 190ad30f8e7SGabor Kovesdan s0 = *s; 191ad30f8e7SGabor Kovesdan 192ad30f8e7SGabor Kovesdan if (s0 == NULL) { 193ad30f8e7SGabor Kovesdan _citrus_UTF8_init_state(ei, psenc); 194ad30f8e7SGabor Kovesdan *nresult = 0; /* state independent */ 195ad30f8e7SGabor Kovesdan return (0); 196ad30f8e7SGabor Kovesdan } 197ad30f8e7SGabor Kovesdan 198ad30f8e7SGabor Kovesdan /* make sure we have the first byte in the buffer */ 199ad30f8e7SGabor Kovesdan if (psenc->chlen == 0) { 200ad30f8e7SGabor Kovesdan if (n-- < 1) 201ad30f8e7SGabor Kovesdan goto restart; 202ad30f8e7SGabor Kovesdan psenc->ch[psenc->chlen++] = *s0++; 203ad30f8e7SGabor Kovesdan } 204ad30f8e7SGabor Kovesdan 205ad30f8e7SGabor Kovesdan c = _UTF8_count[psenc->ch[0] & 0xff]; 206ad30f8e7SGabor Kovesdan if (c < 1 || c < psenc->chlen) 207ad30f8e7SGabor Kovesdan goto ilseq; 208ad30f8e7SGabor Kovesdan 209ad30f8e7SGabor Kovesdan if (c == 1) 210ad30f8e7SGabor Kovesdan wchar = psenc->ch[0] & 0xff; 211ad30f8e7SGabor Kovesdan else { 212ad30f8e7SGabor Kovesdan while (psenc->chlen < c) { 213ad30f8e7SGabor Kovesdan if (n-- < 1) 214ad30f8e7SGabor Kovesdan goto restart; 215ad30f8e7SGabor Kovesdan psenc->ch[psenc->chlen++] = *s0++; 216ad30f8e7SGabor Kovesdan } 217ad30f8e7SGabor Kovesdan wchar = psenc->ch[0] & (0x7f >> c); 218ad30f8e7SGabor Kovesdan for (i = 1; i < c; i++) { 219ad30f8e7SGabor Kovesdan if ((psenc->ch[i] & 0xc0) != 0x80) 220ad30f8e7SGabor Kovesdan goto ilseq; 221ad30f8e7SGabor Kovesdan wchar <<= 6; 222ad30f8e7SGabor Kovesdan wchar |= (psenc->ch[i] & 0x3f); 223ad30f8e7SGabor Kovesdan } 224ad30f8e7SGabor Kovesdan if (_UTF8_surrogate(wchar) || _UTF8_findlen(wchar) != c) 225ad30f8e7SGabor Kovesdan goto ilseq; 226ad30f8e7SGabor Kovesdan } 227ad30f8e7SGabor Kovesdan if (pwc != NULL) 228ad30f8e7SGabor Kovesdan *pwc = wchar; 229ad30f8e7SGabor Kovesdan *nresult = (wchar == 0) ? 0 : s0 - *s; 230ad30f8e7SGabor Kovesdan *s = s0; 231ad30f8e7SGabor Kovesdan psenc->chlen = 0; 232ad30f8e7SGabor Kovesdan 233ad30f8e7SGabor Kovesdan return (0); 234ad30f8e7SGabor Kovesdan 235ad30f8e7SGabor Kovesdan ilseq: 236ad30f8e7SGabor Kovesdan *nresult = (size_t)-1; 237ad30f8e7SGabor Kovesdan return (EILSEQ); 238ad30f8e7SGabor Kovesdan 239ad30f8e7SGabor Kovesdan restart: 240ad30f8e7SGabor Kovesdan *s = s0; 241ad30f8e7SGabor Kovesdan *nresult = (size_t)-2; 242ad30f8e7SGabor Kovesdan return (0); 243ad30f8e7SGabor Kovesdan } 244ad30f8e7SGabor Kovesdan 245ad30f8e7SGabor Kovesdan static int 246ad30f8e7SGabor Kovesdan _citrus_UTF8_wcrtomb_priv(_UTF8EncodingInfo *ei __unused, char *s, size_t n, 247ad30f8e7SGabor Kovesdan wchar_t wc, _UTF8State *psenc __unused, size_t *nresult) 248ad30f8e7SGabor Kovesdan { 249ad30f8e7SGabor Kovesdan wchar_t c; 250ad30f8e7SGabor Kovesdan size_t cnt; 251ad30f8e7SGabor Kovesdan int i, ret; 252ad30f8e7SGabor Kovesdan 253ad30f8e7SGabor Kovesdan if (_UTF8_surrogate(wc)) { 254ad30f8e7SGabor Kovesdan ret = EILSEQ; 255ad30f8e7SGabor Kovesdan goto err; 256ad30f8e7SGabor Kovesdan } 257ad30f8e7SGabor Kovesdan cnt = _UTF8_findlen(wc); 258ad30f8e7SGabor Kovesdan if (cnt <= 0 || cnt > 6) { 259ad30f8e7SGabor Kovesdan /* invalid UCS4 value */ 260ad30f8e7SGabor Kovesdan ret = EILSEQ; 261ad30f8e7SGabor Kovesdan goto err; 262ad30f8e7SGabor Kovesdan } 263ad30f8e7SGabor Kovesdan if (n < cnt) { 264ad30f8e7SGabor Kovesdan /* bound check failure */ 265ad30f8e7SGabor Kovesdan ret = E2BIG; 266ad30f8e7SGabor Kovesdan goto err; 267ad30f8e7SGabor Kovesdan } 268ad30f8e7SGabor Kovesdan 269ad30f8e7SGabor Kovesdan c = wc; 270ad30f8e7SGabor Kovesdan if (s) { 271ad30f8e7SGabor Kovesdan for (i = cnt - 1; i > 0; i--) { 272ad30f8e7SGabor Kovesdan s[i] = 0x80 | (c & 0x3f); 273ad30f8e7SGabor Kovesdan c >>= 6; 274ad30f8e7SGabor Kovesdan } 275ad30f8e7SGabor Kovesdan s[0] = c; 276ad30f8e7SGabor Kovesdan if (cnt == 1) 277ad30f8e7SGabor Kovesdan s[0] &= 0x7f; 278ad30f8e7SGabor Kovesdan else { 279ad30f8e7SGabor Kovesdan s[0] &= (0x7f >> cnt); 280ad30f8e7SGabor Kovesdan s[0] |= ((0xff00 >> cnt) & 0xff); 281ad30f8e7SGabor Kovesdan } 282ad30f8e7SGabor Kovesdan } 283ad30f8e7SGabor Kovesdan 284ad30f8e7SGabor Kovesdan *nresult = (size_t)cnt; 285ad30f8e7SGabor Kovesdan return (0); 286ad30f8e7SGabor Kovesdan 287ad30f8e7SGabor Kovesdan err: 288ad30f8e7SGabor Kovesdan *nresult = (size_t)-1; 289ad30f8e7SGabor Kovesdan return (ret); 290ad30f8e7SGabor Kovesdan } 291ad30f8e7SGabor Kovesdan 292ad30f8e7SGabor Kovesdan static __inline int 293ad30f8e7SGabor Kovesdan /*ARGSUSED*/ 294ad30f8e7SGabor Kovesdan _citrus_UTF8_stdenc_wctocs(_UTF8EncodingInfo * __restrict ei __unused, 295ad30f8e7SGabor Kovesdan _csid_t * __restrict csid, _index_t * __restrict idx, 296ad30f8e7SGabor Kovesdan wchar_t wc) 297ad30f8e7SGabor Kovesdan { 298ad30f8e7SGabor Kovesdan 299ad30f8e7SGabor Kovesdan *csid = 0; 300ad30f8e7SGabor Kovesdan *idx = (_citrus_index_t)wc; 301ad30f8e7SGabor Kovesdan 302ad30f8e7SGabor Kovesdan return (0); 303ad30f8e7SGabor Kovesdan } 304ad30f8e7SGabor Kovesdan 305ad30f8e7SGabor Kovesdan static __inline int 306ad30f8e7SGabor Kovesdan /*ARGSUSED*/ 307ad30f8e7SGabor Kovesdan _citrus_UTF8_stdenc_cstowc(_UTF8EncodingInfo * __restrict ei __unused, 308ad30f8e7SGabor Kovesdan wchar_t * __restrict wc, _csid_t csid, _index_t idx) 309ad30f8e7SGabor Kovesdan { 310ad30f8e7SGabor Kovesdan 311ad30f8e7SGabor Kovesdan if (csid != 0) 312ad30f8e7SGabor Kovesdan return (EILSEQ); 313ad30f8e7SGabor Kovesdan 314ad30f8e7SGabor Kovesdan *wc = (wchar_t)idx; 315ad30f8e7SGabor Kovesdan 316ad30f8e7SGabor Kovesdan return (0); 317ad30f8e7SGabor Kovesdan } 318ad30f8e7SGabor Kovesdan 319ad30f8e7SGabor Kovesdan static __inline int 320ad30f8e7SGabor Kovesdan /*ARGSUSED*/ 321ad30f8e7SGabor Kovesdan _citrus_UTF8_stdenc_get_state_desc_generic(_UTF8EncodingInfo * __restrict ei __unused, 322ad30f8e7SGabor Kovesdan _UTF8State * __restrict psenc, int * __restrict rstate) 323ad30f8e7SGabor Kovesdan { 324ad30f8e7SGabor Kovesdan 325ad30f8e7SGabor Kovesdan *rstate = (psenc->chlen == 0) ? _STDENC_SDGEN_INITIAL : 326ad30f8e7SGabor Kovesdan _STDENC_SDGEN_INCOMPLETE_CHAR; 327ad30f8e7SGabor Kovesdan return (0); 328ad30f8e7SGabor Kovesdan } 329ad30f8e7SGabor Kovesdan 330ad30f8e7SGabor Kovesdan static int 331ad30f8e7SGabor Kovesdan /*ARGSUSED*/ 332ad30f8e7SGabor Kovesdan _citrus_UTF8_encoding_module_init(_UTF8EncodingInfo * __restrict ei __unused, 333ad30f8e7SGabor Kovesdan const void * __restrict var __unused, size_t lenvar __unused) 334ad30f8e7SGabor Kovesdan { 335ad30f8e7SGabor Kovesdan 336ad30f8e7SGabor Kovesdan return (0); 337ad30f8e7SGabor Kovesdan } 338ad30f8e7SGabor Kovesdan 339ad30f8e7SGabor Kovesdan static void 340ad30f8e7SGabor Kovesdan /*ARGSUSED*/ 341ad30f8e7SGabor Kovesdan _citrus_UTF8_encoding_module_uninit(_UTF8EncodingInfo *ei __unused) 342ad30f8e7SGabor Kovesdan { 343ad30f8e7SGabor Kovesdan 344ad30f8e7SGabor Kovesdan } 345ad30f8e7SGabor Kovesdan 346ad30f8e7SGabor Kovesdan /* ---------------------------------------------------------------------- 347ad30f8e7SGabor Kovesdan * public interface for stdenc 348ad30f8e7SGabor Kovesdan */ 349ad30f8e7SGabor Kovesdan 350ad30f8e7SGabor Kovesdan _CITRUS_STDENC_DECLS(UTF8); 351ad30f8e7SGabor Kovesdan _CITRUS_STDENC_DEF_OPS(UTF8); 352ad30f8e7SGabor Kovesdan 353ad30f8e7SGabor Kovesdan #include "citrus_stdenc_template.h" 354