1 #ifndef LIBRARIES_ICONV_H 2 #define LIBRARIES_ICONV_H 3 4 /* 5 * Copyright © 2007 The MorphOS Development Team, All Rights Reserved. 6 */ 7 8 /* Copyright (C) 1999-2003, 2005-2006 Free Software Foundation, Inc. 9 This file is part of the GNU LIBICONV Library. 10 11 The GNU LIBICONV Library is free software; you can redistribute it 12 and/or modify it under the terms of the GNU Library General Public 13 License as published by the Free Software Foundation; either version 2 14 of the License, or (at your option) any later version. 15 16 The GNU LIBICONV Library is distributed in the hope that it will be 17 useful, but WITHOUT ANY WARRANTY; without even the implied warranty of 18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 19 Library General Public License for more details. 20 21 You should have received a copy of the GNU Library General Public 22 License along with the GNU LIBICONV Library; see the file COPYING.LIB. 23 If not, write to the Free Software Foundation, Inc., 51 Franklin Street, 24 Fifth Floor, Boston, MA 02110-1301, USA. */ 25 26 /* When installed, this file is called "iconv.h". */ 27 28 #ifndef _LIBICONV_H 29 #define _LIBICONV_H 30 31 #define _LIBICONV_VERSION 0x010B /* version number: (major<<8) + minor */ 32 33 #if 0 && BUILDING_LIBICONV 34 #define LIBICONV_DLL_EXPORTED __attribute__((__visibility__("default"))) 35 #else 36 #define LIBICONV_DLL_EXPORTED 37 #endif 38 extern LIBICONV_DLL_EXPORTED int _libiconv_version; /* Likewise */ 39 40 /* We would like to #include any system header file which could define 41 iconv_t, 1. in order to eliminate the risk that the user gets compilation 42 errors because some other system header file includes /usr/include/iconv.h 43 which defines iconv_t or declares iconv after this file, 2. when compiling 44 for LIBICONV_PLUG, we need the proper iconv_t type in order to produce 45 binary compatible code. 46 But gcc's #include_next is not portable. Thus, once libiconv's iconv.h 47 has been installed in /usr/local/include, there is no way any more to 48 include the original /usr/include/iconv.h. We simply have to get away 49 without it. 50 Ad 1. The risk that a system header file does 51 #include "iconv.h" or #include_next "iconv.h" 52 is small. They all do #include <iconv.h>. 53 Ad 2. The iconv_t type is a pointer type in all cases I have seen. (It 54 has to be a scalar type because (iconv_t)(-1) is a possible return value 55 from iconv_open().) */ 56 57 /* Define iconv_t ourselves. */ 58 #undef iconv_t 59 #define iconv_t libiconv_t 60 typedef void* iconv_t; 61 62 /* Get size_t declaration. 63 Get wchar_t declaration if it exists. */ 64 #include <stddef.h> 65 66 /* Get errno declaration and values. */ 67 #include <errno.h> 68 /* Some systems, like SunOS 4, don't have EILSEQ. Some systems, like BSD/OS, 69 have EILSEQ in a different header. On these systems, define EILSEQ 70 ourselves. */ 71 #ifndef EILSEQ 72 #define EILSEQ ENOENT 73 #endif 74 75 76 #ifdef __cplusplus 77 extern "C" { 78 #endif 79 80 81 /* Allocates descriptor for code conversion from encoding `fromcode' to 82 encoding `tocode'. */ 83 #ifndef LIBICONV_PLUG 84 #define iconv_open libiconv_open 85 #endif 86 extern LIBICONV_DLL_EXPORTED iconv_t iconv_open (const char* tocode, const char* fromcode); 87 88 /* Converts, using conversion descriptor `cd', at most `*inbytesleft' bytes 89 starting at `*inbuf', writing at most `*outbytesleft' bytes starting at 90 `*outbuf'. 91 Decrements `*inbytesleft' and increments `*inbuf' by the same amount. 92 Decrements `*outbytesleft' and increments `*outbuf' by the same amount. */ 93 #ifndef LIBICONV_PLUG 94 #define iconv libiconv 95 #endif 96 extern LIBICONV_DLL_EXPORTED size_t iconv (iconv_t cd, const char* * inbuf, size_t *inbytesleft, char* * outbuf, size_t *outbytesleft); 97 98 /* Frees resources allocated for conversion descriptor `cd'. */ 99 #ifndef LIBICONV_PLUG 100 #define iconv_close libiconv_close 101 #endif 102 extern LIBICONV_DLL_EXPORTED int iconv_close (iconv_t cd); 103 104 105 #ifndef LIBICONV_PLUG 106 107 /* Nonstandard extensions. */ 108 109 /* Control of attributes. */ 110 #define iconvctl libiconvctl 111 extern LIBICONV_DLL_EXPORTED int iconvctl (iconv_t cd, int request, void* argument); 112 113 /* Hook performed after every successful conversion of a Unicode character. */ 114 typedef void (*iconv_unicode_char_hook) (unsigned int uc, void* data); 115 /* Hook performed after every successful conversion of a wide character. */ 116 typedef void (*iconv_wide_char_hook) (wchar_t wc, void* data); 117 /* Set of hooks. */ 118 struct iconv_hooks { 119 iconv_unicode_char_hook uc_hook; 120 iconv_wide_char_hook wc_hook; 121 void* data; 122 }; 123 124 /* Fallback function. Invoked when a small number of bytes could not be 125 converted to a Unicode character. This function should process all 126 bytes from inbuf and may produce replacement Unicode characters by calling 127 the write_replacement callback repeatedly. */ 128 typedef void (*iconv_unicode_mb_to_uc_fallback) 129 (const char* inbuf, size_t inbufsize, 130 void (*write_replacement) (const unsigned int *buf, size_t buflen, 131 void* callback_arg), 132 void* callback_arg, 133 void* data); 134 /* Fallback function. Invoked when a Unicode character could not be converted 135 to the target encoding. This function should process the character and 136 may produce replacement bytes (in the target encoding) by calling the 137 write_replacement callback repeatedly. */ 138 typedef void (*iconv_unicode_uc_to_mb_fallback) 139 (unsigned int code, 140 void (*write_replacement) (const char *buf, size_t buflen, 141 void* callback_arg), 142 void* callback_arg, 143 void* data); 144 #if 1 145 /* Fallback function. Invoked when a number of bytes could not be converted to 146 a wide character. This function should process all bytes from inbuf and may 147 produce replacement wide characters by calling the write_replacement 148 callback repeatedly. */ 149 typedef void (*iconv_wchar_mb_to_wc_fallback) 150 (const char* inbuf, size_t inbufsize, 151 void (*write_replacement) (const wchar_t *buf, size_t buflen, 152 void* callback_arg), 153 void* callback_arg, 154 void* data); 155 /* Fallback function. Invoked when a wide character could not be converted to 156 the target encoding. This function should process the character and may 157 produce replacement bytes (in the target encoding) by calling the 158 write_replacement callback repeatedly. */ 159 typedef void (*iconv_wchar_wc_to_mb_fallback) 160 (wchar_t code, 161 void (*write_replacement) (const char *buf, size_t buflen, 162 void* callback_arg), 163 void* callback_arg, 164 void* data); 165 #else 166 /* If the wchar_t type does not exist, these two fallback functions are never 167 invoked. Their argument list therefore does not matter. */ 168 typedef void (*iconv_wchar_mb_to_wc_fallback) (); 169 typedef void (*iconv_wchar_wc_to_mb_fallback) (); 170 #endif 171 /* Set of fallbacks. */ 172 struct iconv_fallbacks { 173 iconv_unicode_mb_to_uc_fallback mb_to_uc_fallback; 174 iconv_unicode_uc_to_mb_fallback uc_to_mb_fallback; 175 iconv_wchar_mb_to_wc_fallback mb_to_wc_fallback; 176 iconv_wchar_wc_to_mb_fallback wc_to_mb_fallback; 177 void* data; 178 }; 179 180 /* Requests for iconvctl. */ 181 #define ICONV_TRIVIALP 0 /* int *argument */ 182 #define ICONV_GET_TRANSLITERATE 1 /* int *argument */ 183 #define ICONV_SET_TRANSLITERATE 2 /* const int *argument */ 184 #define ICONV_GET_DISCARD_ILSEQ 3 /* int *argument */ 185 #define ICONV_SET_DISCARD_ILSEQ 4 /* const int *argument */ 186 #define ICONV_SET_HOOKS 5 /* const struct iconv_hooks *argument */ 187 #define ICONV_SET_FALLBACKS 6 /* const struct iconv_fallbacks *argument */ 188 189 /* Listing of locale independent encodings. */ 190 #define iconvlist libiconvlist 191 extern LIBICONV_DLL_EXPORTED void iconvlist (int (*do_one) (unsigned int namescount, 192 const char * const * names, 193 void* data), 194 void* data); 195 196 /* Canonicalize an encoding name. 197 The result is either a canonical encoding name, or name itself. */ 198 extern LIBICONV_DLL_EXPORTED const char * iconv_canonicalize (const char * name); 199 200 /* Support for relocatable packages. */ 201 202 /* Sets the original and the current installation prefix of the package. 203 Relocation simply replaces a pathname starting with the original prefix 204 by the corresponding pathname with the current prefix instead. Both 205 prefixes should be directory names without trailing slash (i.e. use "" 206 instead of "/"). */ 207 extern LIBICONV_DLL_EXPORTED void libiconv_set_relocation_prefix (const char *orig_prefix, 208 const char *curr_prefix); 209 210 #endif 211 212 213 #ifdef __cplusplus 214 } 215 #endif 216 217 218 #endif /* _LIBICONV_H */ 219 220 #endif /* LIBRARIES_ICONV_H */