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