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