iconv.h 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  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, 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 0x010E /* 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. #ifdef __cplusplus
  80. }
  81. #endif
  82. #ifndef LIBICONV_PLUG
  83. /* Nonstandard extensions. */
  84. #if 1
  85. #if 0
  86. /* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
  87. <wchar.h>.
  88. BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
  89. included before <wchar.h>. */
  90. #include <stddef.h>
  91. #include <stdio.h>
  92. #include <time.h>
  93. #endif
  94. #include <wchar.h>
  95. #endif
  96. #ifdef __cplusplus
  97. extern "C" {
  98. #endif
  99. /* A type that holds all memory needed by a conversion descriptor.
  100. A pointer to such an object can be used as an iconv_t. */
  101. typedef struct {
  102. void* dummy1[28];
  103. #if 1
  104. mbstate_t dummy2;
  105. #endif
  106. } iconv_allocation_t;
  107. /* Allocates descriptor for code conversion from encoding ‘fromcode’ to
  108. encoding ‘tocode’ into preallocated memory. Returns an error indicator
  109. (0 or -1 with errno set). */
  110. #define iconv_open_into libiconv_open_into
  111. extern LIBICONV_DLL_EXPORTED int iconv_open_into (const char* tocode, const char* fromcode,
  112. iconv_allocation_t* resultp);
  113. /* Control of attributes. */
  114. #define iconvctl libiconvctl
  115. extern LIBICONV_DLL_EXPORTED int iconvctl (iconv_t cd, int request, void* argument);
  116. /* Hook performed after every successful conversion of a Unicode character. */
  117. typedef void (*iconv_unicode_char_hook) (unsigned int uc, void* data);
  118. /* Hook performed after every successful conversion of a wide character. */
  119. typedef void (*iconv_wide_char_hook) (wchar_t wc, void* data);
  120. /* Set of hooks. */
  121. struct iconv_hooks {
  122. iconv_unicode_char_hook uc_hook;
  123. iconv_wide_char_hook wc_hook;
  124. void* data;
  125. };
  126. /* Fallback function. Invoked when a small number of bytes could not be
  127. converted to a Unicode character. This function should process all
  128. bytes from inbuf and may produce replacement Unicode characters by calling
  129. the write_replacement callback repeatedly. */
  130. typedef void (*iconv_unicode_mb_to_uc_fallback)
  131. (const char* inbuf, size_t inbufsize,
  132. void (*write_replacement) (const unsigned int *buf, size_t buflen,
  133. void* callback_arg),
  134. void* callback_arg,
  135. void* data);
  136. /* Fallback function. Invoked when a Unicode character could not be converted
  137. to the target encoding. This function should process the character and
  138. may produce replacement bytes (in the target encoding) by calling the
  139. write_replacement callback repeatedly. */
  140. typedef void (*iconv_unicode_uc_to_mb_fallback)
  141. (unsigned int code,
  142. void (*write_replacement) (const char *buf, size_t buflen,
  143. void* callback_arg),
  144. void* callback_arg,
  145. void* data);
  146. #if 1
  147. /* Fallback function. Invoked when a number of bytes could not be converted to
  148. a wide character. This function should process all bytes from inbuf and may
  149. produce replacement wide characters by calling the write_replacement
  150. callback repeatedly. */
  151. typedef void (*iconv_wchar_mb_to_wc_fallback)
  152. (const char* inbuf, size_t inbufsize,
  153. void (*write_replacement) (const wchar_t *buf, size_t buflen,
  154. void* callback_arg),
  155. void* callback_arg,
  156. void* data);
  157. /* Fallback function. Invoked when a wide character could not be converted to
  158. the target encoding. This function should process the character and may
  159. produce replacement bytes (in the target encoding) by calling the
  160. write_replacement callback repeatedly. */
  161. typedef void (*iconv_wchar_wc_to_mb_fallback)
  162. (wchar_t code,
  163. void (*write_replacement) (const char *buf, size_t buflen,
  164. void* callback_arg),
  165. void* callback_arg,
  166. void* data);
  167. #else
  168. /* If the wchar_t type does not exist, these two fallback functions are never
  169. invoked. Their argument list therefore does not matter. */
  170. typedef void (*iconv_wchar_mb_to_wc_fallback) ();
  171. typedef void (*iconv_wchar_wc_to_mb_fallback) ();
  172. #endif
  173. /* Set of fallbacks. */
  174. struct iconv_fallbacks {
  175. iconv_unicode_mb_to_uc_fallback mb_to_uc_fallback;
  176. iconv_unicode_uc_to_mb_fallback uc_to_mb_fallback;
  177. iconv_wchar_mb_to_wc_fallback mb_to_wc_fallback;
  178. iconv_wchar_wc_to_mb_fallback wc_to_mb_fallback;
  179. void* data;
  180. };
  181. /* Requests for iconvctl. */
  182. #define ICONV_TRIVIALP 0 /* int *argument */
  183. #define ICONV_GET_TRANSLITERATE 1 /* int *argument */
  184. #define ICONV_SET_TRANSLITERATE 2 /* const int *argument */
  185. #define ICONV_GET_DISCARD_ILSEQ 3 /* int *argument */
  186. #define ICONV_SET_DISCARD_ILSEQ 4 /* const int *argument */
  187. #define ICONV_SET_HOOKS 5 /* const struct iconv_hooks *argument */
  188. #define ICONV_SET_FALLBACKS 6 /* const struct iconv_fallbacks *argument */
  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. /* Canonicalize an encoding name.
  196. The result is either a canonical encoding name, or name itself. */
  197. extern LIBICONV_DLL_EXPORTED const char * iconv_canonicalize (const char * name);
  198. /* Support for relocatable packages. */
  199. /* Sets the original and the current installation prefix of the package.
  200. Relocation simply replaces a pathname starting with the original prefix
  201. by the corresponding pathname with the current prefix instead. Both
  202. prefixes should be directory names without trailing slash (i.e. use ""
  203. instead of "/"). */
  204. extern LIBICONV_DLL_EXPORTED void libiconv_set_relocation_prefix (const char *orig_prefix,
  205. const char *curr_prefix);
  206. #ifdef __cplusplus
  207. }
  208. #endif
  209. #endif
  210. #endif /* _LIBICONV_H */