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