xref: /netbsd/lib/libc/citrus/citrus_ctype.h (revision bf9ec67e)
1 /*	$NetBSD: citrus_ctype.h,v 1.1 2002/03/17 22:14:19 tshiozak Exp $	*/
2 
3 /*-
4  * Copyright (c)2002 Citrus Project,
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
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.
15  *
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
26  * SUCH DAMAGE.
27  *
28  */
29 
30 #ifndef _CITRUS_CTYPE_H_
31 #define _CITRUS_CTYPE_H_
32 
33 #include "citrus_ctype_local.h"
34 
35 typedef struct _citrus_ctype_rec *_citrus_ctype_t;
36 
37 __BEGIN_DECLS
38 int _citrus_ctype_open(_citrus_ctype_t * __restrict,
39 		       char const * __restrict, void * __restrict,
40 		       size_t, size_t);
41 void _citrus_ctype_close(_citrus_ctype_t);
42 __END_DECLS
43 
44 static __inline unsigned
45 _citrus_ctype_get_mb_cur_max(_citrus_ctype_t cc)
46 {
47 
48 	_DIAGASSERT(cc && cc->cc_ops);
49 	return (*cc->cc_ops->co_get_mb_cur_max)(cc->cc_closure);
50 }
51 
52 static __inline int
53 _citrus_ctype_mblen(_citrus_ctype_t cc, const char *s, size_t n, int *nresult)
54 {
55 
56 	_DIAGASSERT(cc && cc->cc_ops && cc->cc_ops->co_mblen && nresult);
57 	return (*cc->cc_ops->co_mblen)(cc->cc_closure, s, n, nresult);
58 }
59 
60 static __inline int
61 _citrus_ctype_mbrlen(_citrus_ctype_t cc, const char *s, size_t n,
62 		     void *pspriv, size_t *nresult)
63 {
64 
65 	_DIAGASSERT(cc && cc->cc_ops && cc->cc_ops->co_mbrlen && nresult);
66 	return (*cc->cc_ops->co_mbrlen)(cc->cc_closure, s, n, pspriv, nresult);
67 }
68 
69 static __inline int
70 _citrus_ctype_mbrtowc(_citrus_ctype_t cc, wchar_t *pwc, const char *s,
71 		      size_t n, void *pspriv, size_t *nresult)
72 {
73 
74 	_DIAGASSERT(cc && cc->cc_ops && cc->cc_ops->co_mbrtowc);
75 	return (*cc->cc_ops->co_mbrtowc)(cc->cc_closure, pwc, s, n, pspriv,
76 					 nresult);
77 }
78 
79 static __inline int
80 _citrus_ctype_mbsinit(_citrus_ctype_t cc, void const *pspriv, int *nresult)
81 {
82 
83 	_DIAGASSERT(cc && cc->cc_ops && cc->cc_ops->co_mbsinit && nresult);
84 	return (*cc->cc_ops->co_mbsinit)(cc->cc_closure, pspriv, nresult);
85 }
86 
87 static __inline int
88 _citrus_ctype_mbsrtowcs(_citrus_ctype_t cc, wchar_t *pwcs, const char **s,
89 			size_t n, void *pspriv, size_t *nresult)
90 {
91 
92 	_DIAGASSERT(cc && cc->cc_ops && cc->cc_ops->co_mbsrtowcs && nresult);
93 	return (*cc->cc_ops->co_mbsrtowcs)(cc->cc_closure, pwcs, s, n, pspriv,
94 					   nresult);
95 }
96 
97 static __inline int
98 _citrus_ctype_mbstowcs(_citrus_ctype_t cc, wchar_t *pwcs, const char *s,
99 		       size_t n, size_t *nresult)
100 {
101 
102 	_DIAGASSERT(cc && cc->cc_ops && cc->cc_ops->co_mbstowcs && nresult);
103 	return (*cc->cc_ops->co_mbstowcs)(cc->cc_closure, pwcs, s, n, nresult);
104 }
105 
106 static __inline int
107 _citrus_ctype_mbtowc(_citrus_ctype_t cc, wchar_t *pw, const char *s, size_t n,
108 		     int *nresult)
109 {
110 
111 	_DIAGASSERT(cc && cc->cc_ops && cc->cc_ops->co_mbtowc && nresult);
112 	return (*cc->cc_ops->co_mbtowc)(cc->cc_closure, pw, s, n, nresult);
113 }
114 
115 static __inline int
116 _citrus_ctype_wcrtomb(_citrus_ctype_t cc, char *s, wchar_t wc,
117 		      void *pspriv, size_t *nresult)
118 {
119 
120 	_DIAGASSERT(cc && cc->cc_ops && cc->cc_ops->co_wcrtomb && nresult);
121 	return (*cc->cc_ops->co_wcrtomb)(cc->cc_closure, s, wc, pspriv,
122 					 nresult);
123 }
124 
125 static __inline int
126 _citrus_ctype_wcsrtombs(_citrus_ctype_t cc, char *s, const wchar_t **ppwcs,
127 			size_t n, void *pspriv, size_t *nresult)
128 {
129 
130 	_DIAGASSERT(cc && cc->cc_ops && cc->cc_ops->co_wcsrtombs && nresult);
131 	return (*cc->cc_ops->co_wcsrtombs)(cc->cc_closure, s, ppwcs, n,
132 					   pspriv, nresult);
133 }
134 
135 static __inline int
136 _citrus_ctype_wcstombs(_citrus_ctype_t cc, char *s, const wchar_t *wcs,
137 		       size_t n, size_t *nresult)
138 {
139 
140 	_DIAGASSERT(cc && cc->cc_ops && cc->cc_ops->co_wcstombs && nresult);
141 	return (*cc->cc_ops->co_wcstombs)(cc->cc_closure, s, wcs, n, nresult);
142 }
143 
144 static __inline int
145 _citrus_ctype_wctomb(_citrus_ctype_t cc, char *s, wchar_t wc, int *nresult)
146 {
147 
148 	_DIAGASSERT(cc && cc->cc_ops && cc->cc_ops->co_wctomb && nresult);
149 	return (*cc->cc_ops->co_wctomb)(cc->cc_closure, s, wc, nresult);
150 }
151 
152 extern _citrus_ctype_rec_t _citrus_ctype_default;
153 
154 #endif
155