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