| 1 | /*	$FreeBSD$	*/ |
| 2 | /*	$NetBSD: iconv.h,v 1.6 2005/02/03 04:39:32 perry Exp $	*/ |
| 3 | |
| 4 | /*- |
| 5 | * SPDX-License-Identifier: BSD-2-Clause |
| 6 | * |
| 7 | * Copyright (c) 2003 Citrus Project, |
| 8 | * Copyright (c) 2009, 2010 Gabor Kovesdan <gabor@FreeBSD.org> |
| 9 | * All rights reserved. |
| 10 | * |
| 11 | * Redistribution and use in source and binary forms, with or without |
| 12 | * modification, are permitted provided that the following conditions |
| 13 | * are met: |
| 14 | * 1. Redistributions of source code must retain the above copyright |
| 15 | * notice, this list of conditions and the following disclaimer. |
| 16 | * 2. Redistributions in binary form must reproduce the above copyright |
| 17 | * notice, this list of conditions and the following disclaimer in the |
| 18 | * documentation and/or other materials provided with the distribution. |
| 19 | * |
| 20 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND |
| 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 23 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE |
| 24 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 25 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
| 26 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 27 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| 28 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
| 29 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 30 | * SUCH DAMAGE. |
| 31 | * |
| 32 | */ |
| 33 | |
| 34 | #ifndef _ICONV_H_ |
| 35 | #define _ICONV_H_ |
| 36 | |
| 37 | #include <sys/cdefs.h> |
| 38 | #include <sys/types.h> |
| 39 | |
| 40 | #if defined(__APPLE__) && \ |
| 41 | (!defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)) |
| 42 | #include <wchar.h> |
| 43 | #endif |
| 44 | |
| 45 | #ifndef __APPLE__ |
| 46 | #include <sys/cdefs.h> |
| 47 | #include <sys/types.h> |
| 48 | #endif |
| 49 | |
| 50 | #ifdef __cplusplus |
| 51 | typedef	bool	__iconv_bool; |
| 52 | #elif __STDC_VERSION__ >= 199901L |
| 53 | typedef	_Bool	__iconv_bool; |
| 54 | #else |
| 55 | typedef	int	__iconv_bool; |
| 56 | #endif |
| 57 | |
| 58 | struct __tag_iconv_t; |
| 59 | typedef	struct __tag_iconv_t	*iconv_t; |
| 60 | |
| 61 | #ifdef __APPLE__ |
| 62 | #define _LIBICONV_VERSION	0x010B	/* Compatible */ |
| 63 | #endif |
| 64 | |
| 65 | __BEGIN_DECLS |
| 66 | #ifdef __APPLE__ |
| 67 | extern int _libiconv_version; |
| 68 | #endif |
| 69 | |
| 70 | iconv_t	iconv_open(const char *, const char *); |
| 71 | size_t	iconv(iconv_t, char ** __restrict, |
| 72 | 	 size_t * __restrict, char ** __restrict, |
| 73 | 	 size_t * __restrict); |
| 74 | int	iconv_close(iconv_t); |
| 75 | |
| 76 | #if defined(__APPLE__) && \ |
| 77 | (!defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)) |
| 78 | /* |
| 79 | * non-portable interfaces for iconv |
| 80 | */ |
| 81 | int	__iconv_get_list(char ***, size_t *, __iconv_bool); |
| 82 | void	__iconv_free_list(char **, size_t); |
| 83 | size_t	__iconv(iconv_t, char **, size_t *, char **, |
| 84 | 		 size_t *, __uint32_t, size_t *); |
| 85 | #define __ICONV_F_HIDE_INVALID	0x0001 |
| 86 | |
| 87 | /* |
| 88 | * GNU interfaces for iconv |
| 89 | */ |
| 90 | typedef struct { |
| 91 | 	void	*spaceholder[64]; |
| 92 | } iconv_allocation_t; |
| 93 | |
| 94 | int	 iconv_open_into(const char *, const char *, iconv_allocation_t *); |
| 95 | #ifdef __APPLE__ |
| 96 | void	 libiconv_set_relocation_prefix(const char *, const char *); |
| 97 | #else |
| 98 | void	 iconv_set_relocation_prefix(const char *, const char *); |
| 99 | #endif |
| 100 | |
| 101 | /* |
| 102 | * iconvctl() request macros |
| 103 | */ |
| 104 | #define ICONV_TRIVIALP		0 |
| 105 | #define	ICONV_GET_TRANSLITERATE	1 |
| 106 | #define	ICONV_SET_TRANSLITERATE	2 |
| 107 | #define ICONV_GET_DISCARD_ILSEQ	3 |
| 108 | #define ICONV_SET_DISCARD_ILSEQ	4 |
| 109 | #define ICONV_SET_HOOKS		5 |
| 110 | #define ICONV_SET_FALLBACKS	6 |
| 111 | #define ICONV_GET_ILSEQ_INVALID	128 |
| 112 | #define ICONV_SET_ILSEQ_INVALID	129 |
| 113 | |
| 114 | typedef void (*iconv_unicode_char_hook) (unsigned int mbr, void *data); |
| 115 | typedef void (*iconv_wide_char_hook) (wchar_t wc, void *data); |
| 116 | |
| 117 | struct iconv_hooks { |
| 118 | 	iconv_unicode_char_hook		 uc_hook; |
| 119 | 	iconv_wide_char_hook		 wc_hook; |
| 120 | 	void				*data; |
| 121 | }; |
| 122 | |
| 123 | #ifndef __APPLE__ |
| 124 | /* |
| 125 | * Fallbacks aren't supported but type definitions are provided for |
| 126 | * source compatibility. |
| 127 | */ |
| 128 | #endif |
| 129 | typedef void (*iconv_unicode_mb_to_uc_fallback) (const char*, |
| 130 | 		size_t, void (*write_replacement) (const unsigned int *, |
| 131 | 		size_t, void*),	void*, void*); |
| 132 | typedef void (*iconv_unicode_uc_to_mb_fallback) (unsigned int, |
| 133 | 		void (*write_replacement) (const char *, size_t, void*), |
| 134 | 		void*, void*); |
| 135 | typedef void (*iconv_wchar_mb_to_wc_fallback) (const char*, size_t, |
| 136 | 		void (*write_replacement) (const wchar_t *, size_t, void*), |
| 137 | 		void*, void*); |
| 138 | typedef void (*iconv_wchar_wc_to_mb_fallback) (wchar_t, |
| 139 | 		void (*write_replacement) (const char *, size_t, void*), |
| 140 | 		void*, void*); |
| 141 | |
| 142 | struct iconv_fallbacks { |
| 143 | 	iconv_unicode_mb_to_uc_fallback	 mb_to_uc_fallback; |
| 144 | 	iconv_unicode_uc_to_mb_fallback uc_to_mb_fallback; |
| 145 | 	iconv_wchar_mb_to_wc_fallback	 mb_to_wc_fallback; |
| 146 | 	iconv_wchar_wc_to_mb_fallback	 wc_to_mb_fallback; |
| 147 | 	void				*data; |
| 148 | }; |
| 149 | |
| 150 | |
| 151 | void		 iconvlist(int (*do_one) (unsigned int, const char * const *, |
| 152 | 		 void *), void *); |
| 153 | const char	*iconv_canonicalize(const char *); |
| 154 | int		 iconvctl(iconv_t, int, void *); |
| 155 | #endif	/* __APPLE__ && (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */ |
| 156 | __END_DECLS |
| 157 | |
| 158 | #endif /* !_ICONV_H_ */ |