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