iconv.h.in 9.1 KB

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