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 #include <wchar.h> 41 42 #include <sys/cdefs.h> 43 #include <sys/types.h> 44 45 #ifdef __cplusplus 46 typedef bool __iconv_bool; 47 #elif __STDC_VERSION__ >= 199901L 48 typedef _Bool __iconv_bool; 49 #else 50 typedef int __iconv_bool; 51 #endif 52 53 struct __tag_iconv_t; 54 typedef struct __tag_iconv_t *iconv_t; 55 56 __BEGIN_DECLS 57 iconv_t iconv_open(const char *, const char *); 58 size_t iconv(iconv_t, char ** __restrict, 59 size_t * __restrict, char ** __restrict, 60 size_t * __restrict); 61 int iconv_close(iconv_t); 62 /* 63 * non-portable interfaces for iconv 64 */ 65 int __iconv_get_list(char ***, size_t *, __iconv_bool); 66 void __iconv_free_list(char **, size_t); 67 size_t __iconv(iconv_t, char **, size_t *, char **, 68 size_t *, __uint32_t, size_t *); 69 #define __ICONV_F_HIDE_INVALID 0x0001 70 71 /* 72 * GNU interfaces for iconv 73 */ 74 typedef struct { 75 void *spaceholder[64]; 76 } iconv_allocation_t; 77 78 int iconv_open_into(const char *, const char *, iconv_allocation_t *); 79 void iconv_set_relocation_prefix(const char *, const char *); 80 81 /* 82 * iconvctl() request macros 83 */ 84 #define ICONV_TRIVIALP 0 85 #define ICONV_GET_TRANSLITERATE 1 86 #define ICONV_SET_TRANSLITERATE 2 87 #define ICONV_GET_DISCARD_ILSEQ 3 88 #define ICONV_SET_DISCARD_ILSEQ 4 89 #define ICONV_SET_HOOKS 5 90 #define ICONV_SET_FALLBACKS 6 91 #define ICONV_GET_ILSEQ_INVALID 128 92 #define ICONV_SET_ILSEQ_INVALID 129 93 94 typedef void (*iconv_unicode_char_hook) (unsigned int mbr, void *data); 95 typedef void (*iconv_wide_char_hook) (wchar_t wc, void *data); 96 97 struct iconv_hooks { 98 iconv_unicode_char_hook uc_hook; 99 iconv_wide_char_hook wc_hook; 100 void *data; 101 }; 102 103 /* 104 * Fallbacks aren't supported but type definitions are provided for 105 * source compatibility. 106 */ 107 typedef void (*iconv_unicode_mb_to_uc_fallback) (const char*, 108 size_t, void (*write_replacement) (const unsigned int *, 109 size_t, void*), void*, void*); 110 typedef void (*iconv_unicode_uc_to_mb_fallback) (unsigned int, 111 void (*write_replacement) (const char *, size_t, void*), 112 void*, void*); 113 typedef void (*iconv_wchar_mb_to_wc_fallback) (const char*, size_t, 114 void (*write_replacement) (const wchar_t *, size_t, void*), 115 void*, void*); 116 typedef void (*iconv_wchar_wc_to_mb_fallback) (wchar_t, 117 void (*write_replacement) (const char *, size_t, void*), 118 void*, void*); 119 120 struct iconv_fallbacks { 121 iconv_unicode_mb_to_uc_fallback mb_to_uc_fallback; 122 iconv_unicode_uc_to_mb_fallback uc_to_mb_fallback; 123 iconv_wchar_mb_to_wc_fallback mb_to_wc_fallback; 124 iconv_wchar_wc_to_mb_fallback wc_to_mb_fallback; 125 void *data; 126 }; 127 128 129 void iconvlist(int (*do_one) (unsigned int, const char * const *, 130 void *), void *); 131 const char *iconv_canonicalize(const char *); 132 int iconvctl(iconv_t, int, void *); 133 __END_DECLS 134 135 #endif /* !_ICONV_H_ */ 136