Sync with NetBSD:
[dragonfly.git] / lib / libc / citrus / citrus_stdenc.h
1 /*      $NetBSD: src/lib/libc/citrus/citrus_stdenc.h,v 1.3 2003/07/10 08:50:44 tshiozak Exp $   */
2 /*      $DragonFly: src/lib/libc/citrus/citrus_stdenc.h,v 1.1 2005/03/11 23:33:53 joerg Exp $ */
3
4 /*-
5  * Copyright (c)2003 Citrus Project,
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  *
29  */
30
31 #ifndef _CITRUS_STDENC_H_
32 #define _CITRUS_STDENC_H_
33
34 struct _citrus_stdenc;
35 struct _citrus_stdenc_ops;
36 struct _citrus_stdenc_traits;
37
38 #include "citrus_stdenc_local.h"
39
40 __BEGIN_DECLS
41 int _citrus_stdenc_open(struct _citrus_stdenc * __restrict * __restrict,
42                         char const * __restrict,
43                         const void * __restrict, size_t);
44 void _citrus_stdenc_close(struct _citrus_stdenc *);
45 __END_DECLS
46
47 static __inline int
48 _citrus_stdenc_init_state(struct _citrus_stdenc * __restrict ce,
49                           void * __restrict ps)
50 {
51         _DIAGASSERT(ce && ce->ce_ops && ce->ce_ops->eo_init_state);
52         return (*ce->ce_ops->eo_init_state)(ce, ps);
53 }
54
55 static __inline int
56 _citrus_stdenc_mbtocs(struct _citrus_stdenc * __restrict ce,
57                       _citrus_csid_t * __restrict csid,
58                       _citrus_index_t * __restrict idx,
59                       const char ** __restrict s, size_t n,
60                       void * __restrict ps, size_t * __restrict nresult)
61 {
62         _DIAGASSERT(ce && ce->ce_ops && ce->ce_ops->eo_mbtocs);
63         return (*ce->ce_ops->eo_mbtocs)(ce, csid, idx, s, n, ps, nresult);
64 }
65
66 static __inline int
67 _citrus_stdenc_cstomb(struct _citrus_stdenc * __restrict ce,
68                       char * __restrict s, size_t n,
69                       _citrus_csid_t csid, _citrus_index_t idx,
70                       void * __restrict ps, size_t * __restrict nresult)
71 {
72         _DIAGASSERT(ce && ce->ce_ops && ce->ce_ops->eo_cstomb);
73         return (*ce->ce_ops->eo_cstomb)(ce, s, n, csid, idx, ps, nresult);
74 }
75
76 static __inline int
77 _citrus_stdenc_mbtowc(struct _citrus_stdenc * __restrict ce,
78                       _citrus_wc_t * __restrict wc,
79                       const char ** __restrict s, size_t n,
80                       void * __restrict ps, size_t * __restrict nresult)
81 {
82         _DIAGASSERT(ce && ce->ce_ops && ce->ce_ops->eo_mbtocs);
83         return (*ce->ce_ops->eo_mbtowc)(ce, wc, s, n, ps, nresult);
84 }
85
86 static __inline int
87 _citrus_stdenc_wctomb(struct _citrus_stdenc * __restrict ce,
88                       char * __restrict s, size_t n, _citrus_wc_t wc,
89                       void * __restrict ps, size_t * __restrict nresult)
90 {
91         _DIAGASSERT(ce && ce->ce_ops && ce->ce_ops->eo_cstomb);
92         return (*ce->ce_ops->eo_wctomb)(ce, s, n, wc, ps, nresult);
93 }
94
95 static __inline int
96 _citrus_stdenc_put_state_reset(struct _citrus_stdenc * __restrict ce,
97                                char * __restrict s, size_t n,
98                                void * __restrict ps,
99                                size_t * __restrict nresult)
100 {
101         _DIAGASSERT(ce && ce->ce_ops && ce->ce_ops->eo_put_state_reset);
102         return (*ce->ce_ops->eo_put_state_reset)(ce, s, n, ps, nresult);
103 }
104
105 static __inline size_t
106 _citrus_stdenc_get_state_size(struct _citrus_stdenc *ce)
107 {
108         _DIAGASSERT(ce && ce->ce_traits);
109         return ce->ce_traits->et_state_size;
110 }
111
112 static __inline size_t
113 _citrus_stdenc_get_mb_cur_max(struct _citrus_stdenc *ce)
114 {
115         _DIAGASSERT(ce && ce->ce_traits);
116         return ce->ce_traits->et_mb_cur_max;
117 }
118
119 #endif