iconv.h 9.1 KB

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