iconv.h 9.5 KB

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