1/* Copyright (C) 1999-2019 Free Software Foundation, Inc.
2   This file is part of the GNU LIBICONV Library.
3
4   The GNU LIBICONV Library is free software; you can redistribute it
5   and/or modify it under the terms of the GNU Library General Public
6   License as published by the Free Software Foundation; either version 2
7   of the License, or (at your option) any later version.
8
9   The GNU LIBICONV Library is distributed in the hope that it will be
10   useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
11   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12   Library General Public License for more details.
13
14   You should have received a copy of the GNU Library General Public
15   License along with the GNU LIBICONV Library; see the file COPYING.LIB.
16   If not, see <https://www.gnu.org/licenses/>.  */
17
18/* When installed, this file is called "iconv.h". */
19
20#ifndef _LIBICONV_H
21#define _LIBICONV_H
22
23#ifndef LIBICONV_PLUG
24#define _LIBICONV_VERSION 0x0110    /* version number: (major<<8) + minor */
25extern @DLL_VARIABLE@ int _libiconv_version; /* Likewise */
26#endif
27
28/* We would like to #include any system header file which could define
29   iconv_t, 1. in order to eliminate the risk that the user gets compilation
30   errors because some other system header file includes /usr/include/iconv.h
31   which defines iconv_t or declares iconv after this file, 2. when compiling
32   for LIBICONV_PLUG, we need the proper iconv_t type in order to produce
33   binary compatible code.
34   But gcc's #include_next is not portable. Thus, once libiconv's iconv.h
35   has been installed in /usr/local/include, there is no way any more to
36   include the original /usr/include/iconv.h. We simply have to get away
37   without it.
38   Ad 1. The risk that a system header file does
39   #include "iconv.h"  or  #include_next "iconv.h"
40   is small. They all do #include <iconv.h>.
41   Ad 2. The iconv_t type is a pointer type in all cases I have seen. (It
42   has to be a scalar type because (iconv_t)(-1) is a possible return value
43   from iconv_open().) */
44
45/* Define iconv_t ourselves. */
46#undef iconv_t
47#define iconv_t libiconv_t
48typedef void* iconv_t;
49
50/* Get size_t declaration.
51   Get wchar_t declaration if it exists. */
52#include <stddef.h>
53
54/* Get errno declaration and values. */
55#include <errno.h>
56/* Some systems, like SunOS 4, don't have EILSEQ. Some systems, like BSD/OS,
57   have EILSEQ in a different header.  On these systems, define EILSEQ
58   ourselves. */
59#ifndef EILSEQ
60#define EILSEQ @EILSEQ@
61#endif
62
63
64#ifdef __cplusplus
65extern "C" {
66#endif
67
68
69/* Allocates descriptor for code conversion from encoding ‘fromcode’ to
70   encoding ‘tocode’. */
71#ifndef LIBICONV_PLUG
72#define iconv_open libiconv_open
73#endif
74extern iconv_t iconv_open (const char* tocode, const char* fromcode);
75
76/* Converts, using conversion descriptor ‘cd’, at most ‘*inbytesleft’ bytes
77   starting at ‘*inbuf’, writing at most ‘*outbytesleft’ bytes starting at
78   ‘*outbuf’.
79   Decrements ‘*inbytesleft’ and increments ‘*inbuf’ by the same amount.
80   Decrements ‘*outbytesleft’ and increments ‘*outbuf’ by the same amount. */
81#ifndef LIBICONV_PLUG
82#define iconv libiconv
83#endif
84extern size_t iconv (iconv_t cd, @ICONV_CONST@ char* * inbuf, size_t *inbytesleft, char* * outbuf, size_t *outbytesleft);
85
86/* Frees resources allocated for conversion descriptor ‘cd’. */
87#ifndef LIBICONV_PLUG
88#define iconv_close libiconv_close
89#endif
90extern int iconv_close (iconv_t cd);
91
92
93#ifdef __cplusplus
94}
95#endif
96
97
98
99/* Nonstandard extensions. */
100
101#if @USE_MBSTATE_T@
102#if @BROKEN_WCHAR_H@
103/* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
104   <wchar.h>.
105   BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
106   included before <wchar.h>.  */
107#include <stddef.h>
108#include <stdio.h>
109#include <time.h>
110#endif
111#include <wchar.h>
112#endif
113
114#ifdef __cplusplus
115extern "C" {
116#endif
117
118/* A type that holds all memory needed by a conversion descriptor.
119   A pointer to such an object can be used as an iconv_t. */
120typedef struct {
121  void* dummy1[28];
122#if @USE_MBSTATE_T@
123  mbstate_t dummy2;
124#endif
125} iconv_allocation_t;
126
127/* Allocates descriptor for code conversion from encoding ‘fromcode’ to
128   encoding ‘tocode’ into preallocated memory. Returns an error indicator
129   (0 or -1 with errno set). */
130#ifndef LIBICONV_PLUG
131#define iconv_open_into libiconv_open_into
132#endif
133extern int iconv_open_into (const char* tocode, const char* fromcode,
134                            iconv_allocation_t* resultp);
135
136/* Control of attributes. */
137#ifndef LIBICONV_PLUG
138#define iconvctl libiconvctl
139#endif
140extern int iconvctl (iconv_t cd, int request, void* argument);
141
142/* Hook performed after every successful conversion of a Unicode character. */
143typedef void (*iconv_unicode_char_hook) (unsigned int uc, void* data);
144/* Hook performed after every successful conversion of a wide character. */
145typedef void (*iconv_wide_char_hook) (wchar_t wc, void* data);
146/* Set of hooks. */
147struct iconv_hooks {
148  iconv_unicode_char_hook uc_hook;
149  iconv_wide_char_hook wc_hook;
150  void* data;
151};
152
153/* Fallback function.  Invoked when a small number of bytes could not be
154   converted to a Unicode character.  This function should process all
155   bytes from inbuf and may produce replacement Unicode characters by calling
156   the write_replacement callback repeatedly.  */
157typedef void (*iconv_unicode_mb_to_uc_fallback)
158             (const char* inbuf, size_t inbufsize,
159              void (*write_replacement) (const unsigned int *buf, size_t buflen,
160                                         void* callback_arg),
161              void* callback_arg,
162              void* data);
163/* Fallback function.  Invoked when a Unicode character could not be converted
164   to the target encoding.  This function should process the character and
165   may produce replacement bytes (in the target encoding) by calling the
166   write_replacement callback repeatedly.  */
167typedef void (*iconv_unicode_uc_to_mb_fallback)
168             (unsigned int code,
169              void (*write_replacement) (const char *buf, size_t buflen,
170                                         void* callback_arg),
171              void* callback_arg,
172              void* data);
173#if @HAVE_WCHAR_T@
174/* Fallback function.  Invoked when a number of bytes could not be converted to
175   a wide character.  This function should process all bytes from inbuf and may
176   produce replacement wide characters by calling the write_replacement
177   callback repeatedly.  */
178typedef void (*iconv_wchar_mb_to_wc_fallback)
179             (const char* inbuf, size_t inbufsize,
180              void (*write_replacement) (const wchar_t *buf, size_t buflen,
181                                         void* callback_arg),
182              void* callback_arg,
183              void* data);
184/* Fallback function.  Invoked when a wide character could not be converted to
185   the target encoding.  This function should process the character and may
186   produce replacement bytes (in the target encoding) by calling the
187   write_replacement callback repeatedly.  */
188typedef void (*iconv_wchar_wc_to_mb_fallback)
189             (wchar_t code,
190              void (*write_replacement) (const char *buf, size_t buflen,
191                                         void* callback_arg),
192              void* callback_arg,
193              void* data);
194#else
195/* If the wchar_t type does not exist, these two fallback functions are never
196   invoked.  Their argument list therefore does not matter.  */
197typedef void (*iconv_wchar_mb_to_wc_fallback) ();
198typedef void (*iconv_wchar_wc_to_mb_fallback) ();
199#endif
200/* Set of fallbacks. */
201struct iconv_fallbacks {
202  iconv_unicode_mb_to_uc_fallback mb_to_uc_fallback;
203  iconv_unicode_uc_to_mb_fallback uc_to_mb_fallback;
204  iconv_wchar_mb_to_wc_fallback mb_to_wc_fallback;
205  iconv_wchar_wc_to_mb_fallback wc_to_mb_fallback;
206  void* data;
207};
208
209/* Requests for iconvctl. */
210#define ICONV_TRIVIALP            0  /* int *argument */
211#define ICONV_GET_TRANSLITERATE   1  /* int *argument */
212#define ICONV_SET_TRANSLITERATE   2  /* const int *argument */
213#define ICONV_GET_DISCARD_ILSEQ   3  /* int *argument */
214#define ICONV_SET_DISCARD_ILSEQ   4  /* const int *argument */
215#define ICONV_SET_HOOKS           5  /* const struct iconv_hooks *argument */
216#define ICONV_SET_FALLBACKS       6  /* const struct iconv_fallbacks *argument */
217#ifdef LIBICONV_PLUG
218#define ICONV_GET_ILSEQ_INVALID 128
219#define ICONV_SET_ILSEQ_INVALID 129
220#endif
221
222/* Listing of locale independent encodings. */
223#ifndef LIBICONV_PLUG
224#define iconvlist libiconvlist
225#endif
226extern void iconvlist (int (*do_one) (unsigned int namescount,
227                                      const char * const * names,
228                                      void* data),
229                       void* data);
230
231/* Canonicalize an encoding name.
232   The result is either a canonical encoding name, or name itself. */
233extern const char * iconv_canonicalize (const char * name);
234
235/* Support for relocatable packages.  */
236
237#ifndef LIBICONV_PLUG
238/* Sets the original and the current installation prefix of the package.
239   Relocation simply replaces a pathname starting with the original prefix
240   by the corresponding pathname with the current prefix instead.  Both
241   prefixes should be directory names without trailing slash (i.e. use ""
242   instead of "/").  */
243extern void libiconv_set_relocation_prefix (const char *orig_prefix,
244                                            const char *curr_prefix);
245#endif
246
247#ifdef __cplusplus
248}
249#endif
250
251
252
253#endif /* _LIBICONV_H */
254