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