iconv.h 9.4 KB

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