iconv.h 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. /* Copyright (C) 1999-2019 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, see <https://www.gnu.org/licenses/>. */
  14. /* When installed, this file is called "iconv.h". */
  15. #ifndef _LIBICONV_H
  16. #define _LIBICONV_H
  17. #define _LIBICONV_VERSION 0x0110 /* version number: (major<<8) + minor */
  18. extern __declspec (dllimport) int _libiconv_version; /* Likewise */
  19. /* We would like to #include any system header file which could define
  20. iconv_t, 1. in order to eliminate the risk that the user gets compilation
  21. errors because some other system header file includes /usr/include/iconv.h
  22. which defines iconv_t or declares iconv after this file, 2. when compiling
  23. for LIBICONV_PLUG, we need the proper iconv_t type in order to produce
  24. binary compatible code.
  25. But gcc's #include_next is not portable. Thus, once libiconv's iconv.h
  26. has been installed in /usr/local/include, there is no way any more to
  27. include the original /usr/include/iconv.h. We simply have to get away
  28. without it.
  29. Ad 1. The risk that a system header file does
  30. #include "iconv.h" or #include_next "iconv.h"
  31. is small. They all do #include <iconv.h>.
  32. Ad 2. The iconv_t type is a pointer type in all cases I have seen. (It
  33. has to be a scalar type because (iconv_t)(-1) is a possible return value
  34. from iconv_open().) */
  35. /* Define iconv_t ourselves. */
  36. #undef iconv_t
  37. #define iconv_t libiconv_t
  38. typedef void* iconv_t;
  39. /* Get size_t declaration.
  40. Get wchar_t declaration if it exists. */
  41. #include <stddef.h>
  42. /* Get errno declaration and values. */
  43. #include <errno.h>
  44. /* Some systems, like SunOS 4, don't have EILSEQ. Some systems, like BSD/OS,
  45. have EILSEQ in a different header. On these systems, define EILSEQ
  46. ourselves. */
  47. #ifndef EILSEQ
  48. #define EILSEQ
  49. #endif
  50. #ifdef __cplusplus
  51. extern "C" {
  52. #endif
  53. /* Allocates descriptor for code conversion from encoding ‘fromcode’ to
  54. encoding ‘tocode’. */
  55. #ifndef LIBICONV_PLUG
  56. #define iconv_open libiconv_open
  57. #endif
  58. extern iconv_t iconv_open (const char* tocode, const char* fromcode);
  59. /* Converts, using conversion descriptor ‘cd’, at most ‘*inbytesleft’ bytes
  60. starting at ‘*inbuf’, writing at most ‘*outbytesleft’ bytes starting at
  61. ‘*outbuf’.
  62. Decrements ‘*inbytesleft’ and increments ‘*inbuf’ by the same amount.
  63. Decrements ‘*outbytesleft’ and increments ‘*outbuf’ by the same amount. */
  64. #ifndef LIBICONV_PLUG
  65. #define iconv libiconv
  66. #endif
  67. extern size_t iconv (iconv_t cd, char* * inbuf, size_t *inbytesleft, char* * outbuf, size_t *outbytesleft);
  68. /* Frees resources allocated for conversion descriptor ‘cd’. */
  69. #ifndef LIBICONV_PLUG
  70. #define iconv_close libiconv_close
  71. #endif
  72. extern int iconv_close (iconv_t cd);
  73. #ifdef __cplusplus
  74. }
  75. #endif
  76. #ifndef LIBICONV_PLUG
  77. /* Nonstandard extensions. */
  78. #if 1
  79. #if 0
  80. /* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
  81. <wchar.h>.
  82. BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
  83. included before <wchar.h>. */
  84. #include <stddef.h>
  85. #include <stdio.h>
  86. #include <time.h>
  87. #endif
  88. #include <wchar.h>
  89. #endif
  90. #ifdef __cplusplus
  91. extern "C" {
  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 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 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 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 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 void libiconv_set_relocation_prefix (const char *orig_prefix,
  199. const char *curr_prefix);
  200. #ifdef __cplusplus
  201. }
  202. #endif
  203. #endif
  204. #endif /* _LIBICONV_H */