xref: /freebsd/include/iconv.h (revision 64038db825d64fb4827fc8ee264ea0fa1a046d82)
1 /*	$NetBSD: iconv.h,v 1.6 2005/02/03 04:39:32 perry Exp $	*/
2 
3 /*-
4  * SPDX-License-Identifier: BSD-2-Clause
5  *
6  * Copyright (c) 2003 Citrus Project,
7  * Copyright (c) 2009, 2010 Gabor Kovesdan <gabor@FreeBSD.org>
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 
33 #ifndef _ICONV_H_
34 #define _ICONV_H_
35 
36 #include <sys/types.h>
37 
38 #include <wchar.h>
39 
40 #if __STDC_VERSION__ >= 202311L || defined(__cplusplus)
41 typedef	bool	__iconv_bool;
42 #elif __STDC_VERSION__ >= 199901L
43 typedef	_Bool	__iconv_bool;
44 #else
45 typedef	int	__iconv_bool;
46 #endif
47 
48 struct __tag_iconv_t;
49 typedef	struct __tag_iconv_t	*iconv_t;
50 
51 __BEGIN_DECLS
52 iconv_t	iconv_open(const char *, const char *);
53 size_t	iconv(iconv_t, char ** __restrict,
54 	      size_t * __restrict, char ** __restrict,
55 	      size_t * __restrict);
56 int	iconv_close(iconv_t);
57 /*
58  * non-portable interfaces for iconv
59  */
60 int	__iconv_get_list(char ***, size_t *, __iconv_bool);
61 void	__iconv_free_list(char **, size_t);
62 size_t	__iconv(iconv_t, char **, size_t *, char **,
63 		     size_t *, __uint32_t, size_t *);
64 #define __ICONV_F_HIDE_INVALID	0x0001
65 
66 /*
67  * GNU interfaces for iconv
68  */
69 typedef struct {
70 	void	*spaceholder[64];
71 } iconv_allocation_t;
72 
73 int	 iconv_open_into(const char *, const char *, iconv_allocation_t *);
74 void	 iconv_set_relocation_prefix(const char *, const char *);
75 
76 /*
77  * iconvctl() request macros
78  */
79 #define ICONV_TRIVIALP		0
80 #define	ICONV_GET_TRANSLITERATE	1
81 #define	ICONV_SET_TRANSLITERATE	2
82 #define ICONV_GET_DISCARD_ILSEQ	3
83 #define ICONV_SET_DISCARD_ILSEQ	4
84 #define ICONV_SET_HOOKS		5
85 #define ICONV_SET_FALLBACKS	6
86 #define ICONV_GET_ILSEQ_INVALID	128
87 #define ICONV_SET_ILSEQ_INVALID	129
88 
89 typedef void (*iconv_unicode_char_hook) (unsigned int mbr, void *data);
90 typedef void (*iconv_wide_char_hook) (wchar_t wc, void *data);
91 
92 struct iconv_hooks {
93 	iconv_unicode_char_hook		 uc_hook;
94 	iconv_wide_char_hook		 wc_hook;
95 	void				*data;
96 };
97 
98 /*
99  * Fallbacks aren't supported but type definitions are provided for
100  * source compatibility.
101  */
102 typedef void (*iconv_unicode_mb_to_uc_fallback) (const char*,
103 		size_t, void (*write_replacement) (const unsigned int *,
104 		size_t, void*),	void*, void*);
105 typedef void (*iconv_unicode_uc_to_mb_fallback) (unsigned int,
106 		void (*write_replacement) (const char *, size_t, void*),
107 		void*, void*);
108 typedef void (*iconv_wchar_mb_to_wc_fallback) (const char*, size_t,
109 		void (*write_replacement) (const wchar_t *, size_t, void*),
110 		void*, void*);
111 typedef void (*iconv_wchar_wc_to_mb_fallback) (wchar_t,
112 		void (*write_replacement) (const char *, size_t, void*),
113 		void*, void*);
114 
115 struct iconv_fallbacks {
116 	iconv_unicode_mb_to_uc_fallback	 mb_to_uc_fallback;
117 	iconv_unicode_uc_to_mb_fallback  uc_to_mb_fallback;
118 	iconv_wchar_mb_to_wc_fallback	 mb_to_wc_fallback;
119 	iconv_wchar_wc_to_mb_fallback	 wc_to_mb_fallback;
120 	void				*data;
121 };
122 
123 
124 void		 iconvlist(int (*do_one) (unsigned int, const char * const *,
125 		    void *), void *);
126 const char	*iconv_canonicalize(const char *);
127 int		 iconvctl(iconv_t, int, void *);
128 __END_DECLS
129 
130 #endif /* !_ICONV_H_ */
131