1 .\" $NetBSD: iconv.3,v 1.21 2013/05/12 10:44:23 wiz Exp $
3 .\" Copyright (c)2003 Citrus Project,
4 .\" All rights reserved.
6 .\" Redistribution and use in source and binary forms, with or without
7 .\" modification, are permitted provided that the following conditions
9 .\" 1. Redistributions of source code must retain the above copyright
10 .\" notice, this list of conditions and the following disclaimer.
11 .\" 2. Redistributions in binary form must reproduce the above copyright
12 .\" notice, this list of conditions and the following disclaimer in the
13 .\" documentation and/or other materials provided with the distribution.
15 .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 .\" ----------------------------------------------------------------------
35 .Nd codeset conversion functions
36 .\" ----------------------------------------------------------------------
39 .\" ----------------------------------------------------------------------
43 .Fn iconv_open "const char *dstname" "const char *srcname"
45 .Fn iconv_close "iconv_t cd"
47 .Fn iconv "iconv_t cd" "const char ** restrict src" "size_t * restrict srcleft" "char ** restrict dst" "size_t * restrict dstleft"
48 .\" ----------------------------------------------------------------------
52 function opens a converter from the codeset
56 and returns its descriptor.
60 function closes the specified converter
65 function converts the string in the buffer
69 bytes and stores the converted string in the buffer
76 the values pointed to by
82 are updated as follows:
83 .Bl -tag -width 01234567 -offset indent
85 Pointer to the byte just after the last character fetched.
87 Number of remaining bytes in the source buffer.
89 Pointer to the byte just after the last character stored.
91 Number of remainder bytes in the destination buffer.
94 If the string pointed to by
96 contains a byte sequence which is not a valid character in the source
97 codeset, the conversion stops just after the last successful conversion.
98 If the output buffer is too small to store the converted
99 character, the conversion also stops in the same way.
100 In these cases, the values pointed to by
106 are updated to the state just after the last successful conversion.
108 If the string pointed to by
110 contains a character which is valid under the source codeset but
111 can not be converted to the destination codeset,
112 the character is replaced by an
113 .Dq invalid character
114 which depends on the destination codeset, e.g.,
116 and the conversion is continued.
118 returns the number of such
119 .Dq invalid conversions .
127 and the source and/or destination codesets are stateful,
129 places these into their initial state.
130 .Bl -enum -offset indent
137 .No non- Ns Dv NULL ,
139 stores the shift sequence for the destination switching to the initial state
140 in the buffer pointed to by
142 The buffer size is specified by the value pointed to by
146 will fail if the buffer is too small to store the shift sequence.
154 In this case, the shift sequence for the destination switching
155 to the initial state is discarded.
157 .\" ----------------------------------------------------------------------
159 Upon successful completion of
161 it returns a conversion descriptor.
164 returns (iconv_t)\-1 and sets
166 to indicate the error.
168 Upon successful completion of
173 returns \-1 and sets errno to indicate the error.
175 Upon successful completion of
177 it returns the number of
182 returns (size_t)\-1 and sets errno to indicate the error.
183 .\" ----------------------------------------------------------------------
187 function may cause an error in the following cases:
190 There is no converter specified by
200 function may cause an error in the following case:
203 The conversion descriptor specified by
210 function may cause an error in the following cases:
213 The output buffer pointed to by
215 is too small to store the result string.
217 The conversion descriptor specified by
221 The string pointed to by
223 contains a byte sequence which does not describe a valid character of
226 The string pointed to by
228 terminates with an incomplete character or shift sequence.
230 .\" ----------------------------------------------------------------------
233 .\" ----------------------------------------------------------------------
242 Historically, the definition of
244 has not been consistent across operating systems.
245 This is due to an unfortunate historical mistake, documented in
246 .Lk https://www5.opengroup.org/sophocles2/show_mail.tpl?&source=L&listname=austin-group-l&id=7404 "this e-mail".
247 The standards page for the header file
249 defined the second argument of
253 but the standards page for the
255 implementation defined it as
257 The standards committee later chose to change the function definition to
258 follow the header file definition
260 even though the version with const is arguably more correct.
262 has always used the const form.
263 It was decided to reject the committee's regression and become
266 GNU libiconv has taken the
267 .Lk http://www.gnu.org/savannah-checkouts/gnu/libiconv/documentation/libiconv-1.14/ "same route".
268 Most third party software affected by this issue already handles it
269 during configuration.
270 .\" ----------------------------------------------------------------------
274 is aborted due to the occurrence of some error,
276 .Dq invalid conversion
277 count mentioned above is unfortunately lost.