xref: /freebsd/lib/libc/iconv/citrus_iconv_local.h (revision cddbc3b40812213ff00041f79174cac0be360a2a)
1 /* $FreeBSD$ */
2 /* $NetBSD: citrus_iconv_local.h,v 1.3 2008/02/09 14:56:20 junyoung Exp $ */
3 
4 /*-
5  * SPDX-License-Identifier: BSD-2-Clause
6  *
7  * Copyright (c)2003 Citrus Project,
8  * All rights reserved.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
20  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
23  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29  * SUCH DAMAGE.
30  */
31 
32 #ifndef _CITRUS_ICONV_LOCAL_H_
33 #define _CITRUS_ICONV_LOCAL_H_
34 
35 #include <iconv.h>
36 #include <stdbool.h>
37 
38 #define _CITRUS_ICONV_GETOPS_FUNC_BASE(_n_)				\
39     int _n_(struct _citrus_iconv_ops *)
40 #define _CITRUS_ICONV_GETOPS_FUNC(_n_)					\
41     _CITRUS_ICONV_GETOPS_FUNC_BASE(_citrus_##_n_##_iconv_getops)
42 
43 #define _CITRUS_ICONV_DECLS(_m_)					\
44 static int	 _citrus_##_m_##_iconv_init_shared			\
45 		    (struct _citrus_iconv_shared * __restrict,		\
46 	 	    const char * __restrict, const char * __restrict);	\
47 static void	 _citrus_##_m_##_iconv_uninit_shared			\
48 		    (struct _citrus_iconv_shared *);			\
49 static int	 _citrus_##_m_##_iconv_convert				\
50 		    (struct _citrus_iconv * __restrict,			\
51 		    char * __restrict * __restrict,			\
52 		    size_t * __restrict,				\
53 		    char * __restrict * __restrict,			\
54 		    size_t * __restrict outbytes,			\
55 	 	    uint32_t, size_t * __restrict);			\
56 static int	 _citrus_##_m_##_iconv_init_context			\
57 		    (struct _citrus_iconv *);				\
58 static void	 _citrus_##_m_##_iconv_uninit_context			\
59 		    (struct _citrus_iconv *)
60 
61 
62 #define _CITRUS_ICONV_DEF_OPS(_m_)					\
63 extern struct _citrus_iconv_ops _citrus_##_m_##_iconv_ops;		\
64 struct _citrus_iconv_ops _citrus_##_m_##_iconv_ops = {			\
65 	/* io_init_shared */	&_citrus_##_m_##_iconv_init_shared,	\
66 	/* io_uninit_shared */	&_citrus_##_m_##_iconv_uninit_shared,	\
67 	/* io_init_context */	&_citrus_##_m_##_iconv_init_context,	\
68 	/* io_uninit_context */	&_citrus_##_m_##_iconv_uninit_context,	\
69 	/* io_convert */	&_citrus_##_m_##_iconv_convert		\
70 }
71 
72 typedef _CITRUS_ICONV_GETOPS_FUNC_BASE((*_citrus_iconv_getops_t));
73 typedef	int (*_citrus_iconv_init_shared_t)
74     (struct _citrus_iconv_shared * __restrict,
75     const char * __restrict, const char * __restrict);
76 typedef void (*_citrus_iconv_uninit_shared_t)
77     (struct _citrus_iconv_shared *);
78 typedef int (*_citrus_iconv_convert_t)
79     (struct _citrus_iconv * __restrict,
80     char *__restrict* __restrict, size_t * __restrict,
81     char * __restrict * __restrict, size_t * __restrict, uint32_t,
82     size_t * __restrict);
83 typedef int (*_citrus_iconv_init_context_t)(struct _citrus_iconv *);
84 typedef void (*_citrus_iconv_uninit_context_t)(struct _citrus_iconv *);
85 
86 struct _citrus_iconv_ops {
87 	_citrus_iconv_init_shared_t	io_init_shared;
88 	_citrus_iconv_uninit_shared_t	io_uninit_shared;
89 	_citrus_iconv_init_context_t	io_init_context;
90 	_citrus_iconv_uninit_context_t	io_uninit_context;
91 	_citrus_iconv_convert_t		io_convert;
92 };
93 
94 struct _citrus_iconv_shared {
95 	struct _citrus_iconv_ops			*ci_ops;
96 	void						*ci_closure;
97 	_CITRUS_HASH_ENTRY(_citrus_iconv_shared)	 ci_hash_entry;
98 	TAILQ_ENTRY(_citrus_iconv_shared)		 ci_tailq_entry;
99 	_citrus_module_t				 ci_module;
100 	unsigned int					 ci_used_count;
101 	char						*ci_convname;
102 	bool						 ci_discard_ilseq;
103 	struct iconv_hooks				*ci_hooks;
104 	bool						 ci_ilseq_invalid;
105 };
106 
107 struct _citrus_iconv {
108 	struct _citrus_iconv_shared			*cv_shared;
109 	void						*cv_closure;
110 };
111 
112 #endif
113