xref: /freebsd/lib/libc/iconv/citrus_iconv_local.h (revision aa0a1e58)
1 /* $FreeBSD$ */
2 /* $NetBSD: citrus_iconv_local.h,v 1.3 2008/02/09 14:56:20 junyoung 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 #ifndef _CITRUS_ICONV_LOCAL_H_
31 #define _CITRUS_ICONV_LOCAL_H_
32 
33 #include <iconv.h>
34 
35 #define _CITRUS_ICONV_GETOPS_FUNC_BASE(_n_)				\
36     int _n_(struct _citrus_iconv_ops *)
37 #define _CITRUS_ICONV_GETOPS_FUNC(_n_)					\
38     _CITRUS_ICONV_GETOPS_FUNC_BASE(_citrus_##_n_##_iconv_getops)
39 
40 #define _CITRUS_ICONV_DECLS(_m_)					\
41 static int	 _citrus_##_m_##_iconv_init_shared			\
42 		    (struct _citrus_iconv_shared * __restrict,		\
43 	 	    const char * __restrict, const char * __restrict);	\
44 static void	 _citrus_##_m_##_iconv_uninit_shared			\
45 		    (struct _citrus_iconv_shared *);			\
46 static int	 _citrus_##_m_##_iconv_convert				\
47 		    (struct _citrus_iconv * __restrict,			\
48 		    char * __restrict * __restrict,			\
49 		    size_t * __restrict,				\
50 		    char * __restrict * __restrict,			\
51 		    size_t * __restrict outbytes,			\
52 	 	    uint32_t, size_t * __restrict);			\
53 static int	 _citrus_##_m_##_iconv_init_context			\
54 		    (struct _citrus_iconv *);				\
55 static void	 _citrus_##_m_##_iconv_uninit_context			\
56 		    (struct _citrus_iconv *)
57 
58 
59 #define _CITRUS_ICONV_DEF_OPS(_m_)					\
60 struct _citrus_iconv_ops _citrus_##_m_##_iconv_ops = {			\
61 	/* io_init_shared */	&_citrus_##_m_##_iconv_init_shared,	\
62 	/* io_uninit_shared */	&_citrus_##_m_##_iconv_uninit_shared,	\
63 	/* io_init_context */	&_citrus_##_m_##_iconv_init_context,	\
64 	/* io_uninit_context */	&_citrus_##_m_##_iconv_uninit_context,	\
65 	/* io_convert */	&_citrus_##_m_##_iconv_convert		\
66 }
67 
68 typedef _CITRUS_ICONV_GETOPS_FUNC_BASE((*_citrus_iconv_getops_t));
69 typedef	int (*_citrus_iconv_init_shared_t)
70     (struct _citrus_iconv_shared * __restrict,
71     const char * __restrict, const char * __restrict);
72 typedef void (*_citrus_iconv_uninit_shared_t)
73     (struct _citrus_iconv_shared *);
74 typedef int (*_citrus_iconv_convert_t)
75     (struct _citrus_iconv * __restrict,
76     char *__restrict* __restrict, size_t * __restrict,
77     char * __restrict * __restrict, size_t * __restrict, uint32_t,
78     size_t * __restrict);
79 typedef int (*_citrus_iconv_init_context_t)(struct _citrus_iconv *);
80 typedef void (*_citrus_iconv_uninit_context_t)(struct _citrus_iconv *);
81 
82 struct _citrus_iconv_ops {
83 	_citrus_iconv_init_shared_t	io_init_shared;
84 	_citrus_iconv_uninit_shared_t	io_uninit_shared;
85 	_citrus_iconv_init_context_t	io_init_context;
86 	_citrus_iconv_uninit_context_t	io_uninit_context;
87 	_citrus_iconv_convert_t		io_convert;
88 };
89 
90 struct _citrus_iconv_shared {
91 	struct _citrus_iconv_ops			*ci_ops;
92 	void						*ci_closure;
93 	_CITRUS_HASH_ENTRY(_citrus_iconv_shared)	 ci_hash_entry;
94 	TAILQ_ENTRY(_citrus_iconv_shared)		 ci_tailq_entry;
95 	_citrus_module_t				 ci_module;
96 	unsigned int					 ci_used_count;
97 	char						*ci_convname;
98 	bool						 ci_discard_ilseq;
99 	struct iconv_hooks				*ci_hooks;
100 };
101 
102 struct _citrus_iconv {
103 	struct _citrus_iconv_shared			*cv_shared;
104 	void						*cv_closure;
105 };
106 
107 #endif
108