iconv.h 9.1 KB

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