1 /* $NetBSD: citrus_ctype.c,v 1.5 2008/06/14 16:01:07 tnozaki Exp $ */
4 * Copyright (c)1999, 2000, 2001, 2002 Citrus Project,
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 #include <sys/cdefs.h>
30 #if defined(LIBC_SCCS) && !defined(lint)
31 __RCSID("$NetBSD: citrus_ctype.c,v 1.5 2008/06/14 16:01:07 tnozaki Exp $");
32 #endif /* LIBC_SCCS and not lint */
34 #include <sys/types.h>
44 #include "citrus_module.h"
45 #include "citrus_ctype.h"
46 #include "citrus_ctype_fallback.h"
47 #include "citrus_none.h"
48 #include _CITRUS_DEFAULT_CTYPE_HEADER
50 _citrus_ctype_rec_t _citrus_ctype_default
= {
51 &_CITRUS_DEFAULT_CTYPE_OPS
, /* cc_ops */
52 NULL
, /* cc_closure */
58 static int _initctypemodule(_citrus_ctype_t
, char const *, _citrus_module_t
,
59 void *, size_t, size_t);
62 _initctypemodule(_citrus_ctype_t cc
, char const *modname
,
63 _citrus_module_t handle
, void *variable
, size_t lenvar
,
67 _citrus_ctype_getops_t getops
;
69 _DIAGASSERT(cc
!= NULL
);
71 cc
->cc_module
= handle
;
73 getops
= (_citrus_ctype_getops_t
)_citrus_find_getops(cc
->cc_module
,
79 cc
->cc_ops
= (_citrus_ctype_ops_rec_t
*)malloc(sizeof(*cc
->cc_ops
));
80 if (cc
->cc_ops
== NULL
)
83 ret
= (*getops
)(cc
->cc_ops
, sizeof(*cc
->cc_ops
),
84 _CITRUS_CTYPE_ABI_VERSION
);
88 /* If return ABI version is not expected, fixup it here*/
89 switch (cc
->cc_ops
->co_abi_version
) {
91 cc
->cc_ops
->co_btowc
= &_citrus_ctype_btowc_fallback
;
92 cc
->cc_ops
->co_wctob
= &_citrus_ctype_wctob_fallback
;
100 /* validation check */
101 if (cc
->cc_ops
->co_init
== NULL
||
102 cc
->cc_ops
->co_uninit
== NULL
||
103 cc
->cc_ops
->co_get_mb_cur_max
== NULL
||
104 cc
->cc_ops
->co_mblen
== NULL
||
105 cc
->cc_ops
->co_mbrlen
== NULL
||
106 cc
->cc_ops
->co_mbrtowc
== NULL
||
107 cc
->cc_ops
->co_mbsinit
== NULL
||
108 cc
->cc_ops
->co_mbsrtowcs
== NULL
||
109 cc
->cc_ops
->co_mbstowcs
== NULL
||
110 cc
->cc_ops
->co_mbtowc
== NULL
||
111 cc
->cc_ops
->co_wcrtomb
== NULL
||
112 cc
->cc_ops
->co_wcsrtombs
== NULL
||
113 cc
->cc_ops
->co_wcstombs
== NULL
||
114 cc
->cc_ops
->co_wctomb
== NULL
||
115 cc
->cc_ops
->co_btowc
== NULL
||
116 cc
->cc_ops
->co_wctob
== NULL
)
119 /* init and get closure */
120 ret
= (*cc
->cc_ops
->co_init
)(
121 &cc
->cc_closure
, variable
, lenvar
, szpriv
);
136 _citrus_ctype_open(_citrus_ctype_t
*rcc
,
137 char const *encname
, void *variable
, size_t lenvar
,
141 _citrus_module_t handle
;
144 _DIAGASSERT(encname
!= NULL
);
145 _DIAGASSERT(!lenvar
|| variable
!=NULL
);
146 _DIAGASSERT(rcc
!= NULL
);
148 if (!strcmp(encname
, _CITRUS_DEFAULT_CTYPE_NAME
)) {
149 *rcc
= &_citrus_ctype_default
;
152 ret
= _citrus_load_module(&handle
, encname
);
156 cc
= calloc(1, sizeof(*cc
));
158 _citrus_unload_module(handle
);
162 ret
= _initctypemodule(cc
, encname
, handle
, variable
, lenvar
, szpriv
);
164 _citrus_unload_module(cc
->cc_module
);
175 _citrus_ctype_close(_citrus_ctype_t cc
)
178 _DIAGASSERT(cc
!= NULL
);
180 if (cc
== &_citrus_ctype_default
)
182 (*cc
->cc_ops
->co_uninit
)(cc
->cc_closure
);
184 _citrus_unload_module(cc
->cc_module
);
193 _citrus_ctype_open(_citrus_ctype_t
*rcc
,
194 char const *encname
, void *variable
, size_t lenvar
,
197 if (!strcmp(encname
, _CITRUS_DEFAULT_CTYPE_NAME
)) {
198 *rcc
= &_citrus_ctype_default
;
206 _citrus_ctype_close(_citrus_ctype_t cc
)