xref: /freebsd/lib/libc/iconv/iconv.3 (revision 9c0b8e489d13132a75efd3d7cad5ad15aa0e2685)
1ad30f8e7SGabor Kovesdan.\" $FreeBSD$
2ad30f8e7SGabor Kovesdan.\" $NetBSD: iconv.3,v 1.12 2004/08/02 13:38:21 tshiozak Exp $
3ad30f8e7SGabor Kovesdan.\"
4ad30f8e7SGabor Kovesdan.\" Copyright (c) 2003 Citrus Project,
5ad30f8e7SGabor Kovesdan.\" Copyright (c) 2009, 2010 Gabor Kovesdan <gabor@FreeBSD.org>,
6ad30f8e7SGabor Kovesdan.\" All rights reserved.
7ad30f8e7SGabor Kovesdan.\"
8ad30f8e7SGabor Kovesdan.\" Redistribution and use in source and binary forms, with or without
9ad30f8e7SGabor Kovesdan.\" modification, are permitted provided that the following conditions
10ad30f8e7SGabor Kovesdan.\" are met:
11ad30f8e7SGabor Kovesdan.\" 1. Redistributions of source code must retain the above copyright
12ad30f8e7SGabor Kovesdan.\"    notice, this list of conditions and the following disclaimer.
13ad30f8e7SGabor Kovesdan.\" 2. Redistributions in binary form must reproduce the above copyright
14ad30f8e7SGabor Kovesdan.\"    notice, this list of conditions and the following disclaimer in the
15ad30f8e7SGabor Kovesdan.\"    documentation and/or other materials provided with the distribution.
16ad30f8e7SGabor Kovesdan.\"
17ad30f8e7SGabor Kovesdan.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18ad30f8e7SGabor Kovesdan.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19ad30f8e7SGabor Kovesdan.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20ad30f8e7SGabor Kovesdan.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21ad30f8e7SGabor Kovesdan.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22ad30f8e7SGabor Kovesdan.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23ad30f8e7SGabor Kovesdan.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24ad30f8e7SGabor Kovesdan.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25ad30f8e7SGabor Kovesdan.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26ad30f8e7SGabor Kovesdan.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27ad30f8e7SGabor Kovesdan.\" SUCH DAMAGE.
28ad30f8e7SGabor Kovesdan.\"
29*9c0b8e48SJohn-Mark Gurney.Dd August 4, 2014
30ad30f8e7SGabor Kovesdan.Dt ICONV 3
31ad30f8e7SGabor Kovesdan.Os
32ad30f8e7SGabor Kovesdan.Sh NAME
33ad30f8e7SGabor Kovesdan.Nm iconv_open ,
34ad30f8e7SGabor Kovesdan.Nm iconv_open_into ,
35ad30f8e7SGabor Kovesdan.Nm iconv_close ,
36ad30f8e7SGabor Kovesdan.Nm iconv
37ad30f8e7SGabor Kovesdan.Nd codeset conversion functions
38ad30f8e7SGabor Kovesdan.Sh LIBRARY
39ad30f8e7SGabor Kovesdan.Lb libc
40ad30f8e7SGabor Kovesdan.Sh SYNOPSIS
41ad30f8e7SGabor Kovesdan.In iconv.h
42ad30f8e7SGabor Kovesdan.Ft iconv_t
43ad30f8e7SGabor Kovesdan.Fn iconv_open "const char *dstname" "const char *srcname"
44ad30f8e7SGabor Kovesdan.Ft int
45ad30f8e7SGabor Kovesdan.Fn iconv_open_into "const char *dstname" "const char *srcname" "iconv_allocation_t *ptr"
46ad30f8e7SGabor Kovesdan.Ft int
47ad30f8e7SGabor Kovesdan.Fn iconv_close "iconv_t cd"
48ad30f8e7SGabor Kovesdan.Ft size_t
49ad30f8e7SGabor Kovesdan.Fn iconv "iconv_t cd" "char ** restrict src" "size_t * restrict srcleft" "char ** restrict dst" "size_t * restrict dstleft"
50ad30f8e7SGabor Kovesdan.Ft size_t
51ad30f8e7SGabor Kovesdan.Fn __iconv "iconv_t cd" "const char ** restrict src" "size_t * restrict srcleft" "char ** restrict dst" "size_t * restrict dstleft" "uint32_t flags" "size_t invalids"
52ad30f8e7SGabor Kovesdan.Sh DESCRIPTION
53ad30f8e7SGabor KovesdanThe
54ad30f8e7SGabor Kovesdan.Fn iconv_open
55ad30f8e7SGabor Kovesdanfunction opens a converter from the codeset
56ad30f8e7SGabor Kovesdan.Fa srcname
57ad30f8e7SGabor Kovesdanto the codeset
58ad30f8e7SGabor Kovesdan.Fa dstname
59ad30f8e7SGabor Kovesdanand returns its descriptor.
60ad30f8e7SGabor KovesdanThe arguments
61ad30f8e7SGabor Kovesdan.Fa srcname
62ad30f8e7SGabor Kovesdanand
63ad30f8e7SGabor Kovesdan.Fa dstname
64ad30f8e7SGabor Kovesdanaccept "" and "char", which refer to the current locale encoding.
65ad30f8e7SGabor Kovesdan.Pp
66ad30f8e7SGabor KovesdanThe
67ad30f8e7SGabor Kovesdan.Fn iconv_open_into
68ad30f8e7SGabor Kovesdancreates a conversion descriptor on a preallocated space.
69ad30f8e7SGabor KovesdanThe
70ad30f8e7SGabor Kovesdan.Ft iconv_allocation_t
71ad30f8e7SGabor Kovesdanis used as a spaceholder type when allocating such space.
72ad30f8e7SGabor KovesdanThe
73ad30f8e7SGabor Kovesdan.Fa dstname
74ad30f8e7SGabor Kovesdanand
75ad30f8e7SGabor Kovesdan.Fa srcname
76ad30f8e7SGabor Kovesdanarguments are the same as in the case of
77ad30f8e7SGabor Kovesdan.Fn iconv_open .
78ad30f8e7SGabor KovesdanThe
79ad30f8e7SGabor Kovesdan.Fa ptr
80ad30f8e7SGabor Kovesdanargument is a pointer of
81ad30f8e7SGabor Kovesdan.Ft iconv_allocation_t
82ad30f8e7SGabor Kovesdanto the preallocated space.
83ad30f8e7SGabor Kovesdan.Pp
84ad30f8e7SGabor KovesdanThe
85ad30f8e7SGabor Kovesdan.Fn iconv_close
86ad30f8e7SGabor Kovesdanfunction closes the specified converter
87ad30f8e7SGabor Kovesdan.Fa cd .
88ad30f8e7SGabor Kovesdan.Pp
89ad30f8e7SGabor KovesdanThe
90ad30f8e7SGabor Kovesdan.Fn iconv
91ad30f8e7SGabor Kovesdanfunction converts the string in the buffer
92ad30f8e7SGabor Kovesdan.Fa *src
93ad30f8e7SGabor Kovesdanof length
94ad30f8e7SGabor Kovesdan.Fa *srcleft
95ad30f8e7SGabor Kovesdanbytes and stores the converted string in the buffer
96ad30f8e7SGabor Kovesdan.Fa *dst
97ad30f8e7SGabor Kovesdanof size
98ad30f8e7SGabor Kovesdan.Fa *dstleft
99ad30f8e7SGabor Kovesdanbytes.
100ad30f8e7SGabor KovesdanAfter calling
101ad30f8e7SGabor Kovesdan.Fn iconv ,
102ad30f8e7SGabor Kovesdanthe values pointed to by
103ad30f8e7SGabor Kovesdan.Fa src ,
104ad30f8e7SGabor Kovesdan.Fa srcleft ,
105ad30f8e7SGabor Kovesdan.Fa dst ,
106ad30f8e7SGabor Kovesdanand
107ad30f8e7SGabor Kovesdan.Fa dstleft
108ad30f8e7SGabor Kovesdanare updated as follows:
109ad30f8e7SGabor Kovesdan.Bl -tag -width 01234567
110ad30f8e7SGabor Kovesdan.It *src
111ad30f8e7SGabor KovesdanPointer to the byte just after the last character fetched.
112ad30f8e7SGabor Kovesdan.It *srcleft
113ad30f8e7SGabor KovesdanNumber of remaining bytes in the source buffer.
114ad30f8e7SGabor Kovesdan.It *dst
115ad30f8e7SGabor KovesdanPointer to the byte just after the last character stored.
116ad30f8e7SGabor Kovesdan.It *dstleft
117ad30f8e7SGabor KovesdanNumber of remainder bytes in the destination buffer.
118ad30f8e7SGabor Kovesdan.El
119ad30f8e7SGabor Kovesdan.Pp
120ad30f8e7SGabor KovesdanIf the string pointed to by
121ad30f8e7SGabor Kovesdan.Fa *src
122ad30f8e7SGabor Kovesdancontains a byte sequence which is not a valid character in the source
123ad30f8e7SGabor Kovesdancodeset, the conversion stops just after the last successful conversion.
124ad30f8e7SGabor KovesdanIf the output buffer is too small to store the converted
125ad30f8e7SGabor Kovesdancharacter, the conversion also stops in the same way.
126ad30f8e7SGabor KovesdanIn these cases, the values pointed to by
127ad30f8e7SGabor Kovesdan.Fa src ,
128ad30f8e7SGabor Kovesdan.Fa srcleft ,
129ad30f8e7SGabor Kovesdan.Fa dst ,
130ad30f8e7SGabor Kovesdanand
131ad30f8e7SGabor Kovesdan.Fa dstleft
132ad30f8e7SGabor Kovesdanare updated to the state just after the last successful conversion.
133ad30f8e7SGabor Kovesdan.Pp
134ad30f8e7SGabor KovesdanIf the string pointed to by
135ad30f8e7SGabor Kovesdan.Fa *src
136ad30f8e7SGabor Kovesdancontains a character which is valid under the source codeset but
137ad30f8e7SGabor Kovesdancan not be converted to the destination codeset,
138ad30f8e7SGabor Kovesdanthe character is replaced by an
139ad30f8e7SGabor Kovesdan.Dq invalid character
140ad30f8e7SGabor Kovesdanwhich depends on the destination codeset, e.g.,
141ad30f8e7SGabor Kovesdan.Sq \&? ,
142ad30f8e7SGabor Kovesdanand the conversion is continued.
143ad30f8e7SGabor Kovesdan.Fn iconv
144ad30f8e7SGabor Kovesdanreturns the number of such
145ad30f8e7SGabor Kovesdan.Dq invalid conversions .
146ad30f8e7SGabor Kovesdan.Pp
147ad30f8e7SGabor KovesdanThere are two special cases of
148ad30f8e7SGabor Kovesdan.Fn iconv :
149ad30f8e7SGabor Kovesdan.Bl -tag -width 0123
150ad30f8e7SGabor Kovesdan.It "src == NULL || *src == NULL"
151ad30f8e7SGabor KovesdanIf the source and/or destination codesets are stateful,
152ad30f8e7SGabor Kovesdan.Fn iconv
153ad30f8e7SGabor Kovesdanplaces these into their initial state.
154ad30f8e7SGabor Kovesdan.Pp
155ad30f8e7SGabor KovesdanIf both
156ad30f8e7SGabor Kovesdan.Fa dst
157ad30f8e7SGabor Kovesdanand
158ad30f8e7SGabor Kovesdan.Fa *dst
159ad30f8e7SGabor Kovesdanare
160ad30f8e7SGabor Kovesdan.No non- Ns Dv NULL ,
161ad30f8e7SGabor Kovesdan.Fn iconv
162ad30f8e7SGabor Kovesdanstores the shift sequence for the destination switching to the initial state
163ad30f8e7SGabor Kovesdanin the buffer pointed to by
164ad30f8e7SGabor Kovesdan.Fa *dst .
165ad30f8e7SGabor KovesdanThe buffer size is specified by the value pointed to by
166ad30f8e7SGabor Kovesdan.Fa dstleft
167ad30f8e7SGabor Kovesdanas above.
168ad30f8e7SGabor Kovesdan.Fn iconv
169ad30f8e7SGabor Kovesdanwill fail if the buffer is too small to store the shift sequence.
170ad30f8e7SGabor Kovesdan.Pp
171ad30f8e7SGabor KovesdanOn the other hand,
172ad30f8e7SGabor Kovesdan.Fa dst
173ad30f8e7SGabor Kovesdanor
174ad30f8e7SGabor Kovesdan.Fa *dst
175ad30f8e7SGabor Kovesdanmay be
176ad30f8e7SGabor Kovesdan.Dv NULL .
177ad30f8e7SGabor KovesdanIn this case, the shift sequence for the destination switching
178ad30f8e7SGabor Kovesdanto the initial state is discarded.
179ad30f8e7SGabor Kovesdan.Pp
180ad30f8e7SGabor Kovesdan.El
181ad30f8e7SGabor KovesdanThe
182ad30f8e7SGabor Kovesdan.Fn __iconv
183ad30f8e7SGabor Kovesdanfunction works just like
184ad30f8e7SGabor Kovesdan.Fn iconv
185ad30f8e7SGabor Kovesdanbut if
186ad30f8e7SGabor Kovesdan.Fn iconv
187ad30f8e7SGabor Kovesdanfails, the invalid character count is lost there.
188ad30f8e7SGabor KovesdanThis is a not bug rather a limitation of
189ad30f8e7SGabor Kovesdan.St -p1003.1-2008 ,
190ad30f8e7SGabor Kovesdanso
191ad30f8e7SGabor Kovesdan.Fn __iconv
192ad30f8e7SGabor Kovesdanis provided as an alternative but non-standard interface.
193ad30f8e7SGabor KovesdanIt also has a flags argument, where currently the following
194ad30f8e7SGabor Kovesdanflags can be passed:
195ad30f8e7SGabor Kovesdan.Bl -tag -width 0123
196ad30f8e7SGabor Kovesdan.It __ICONV_F_HIDE_INVALID
197ad30f8e7SGabor KovesdanSkip invalid characters, instead of returning with an error.
198ad30f8e7SGabor Kovesdan.El
199ad30f8e7SGabor Kovesdan.Sh RETURN VALUES
200ad30f8e7SGabor KovesdanUpon successful completion of
201ad30f8e7SGabor Kovesdan.Fn iconv_open ,
202ad30f8e7SGabor Kovesdanit returns a conversion descriptor.
203ad30f8e7SGabor KovesdanOtherwise,
204ad30f8e7SGabor Kovesdan.Fn iconv_open
205ad30f8e7SGabor Kovesdanreturns (iconv_t)\-1 and sets errno to indicate the error.
206ad30f8e7SGabor Kovesdan.Pp
207ad30f8e7SGabor KovesdanUpon successful completion of
208ad30f8e7SGabor Kovesdan.Fn iconv_open_into ,
209ad30f8e7SGabor Kovesdanit returns 0.
210ad30f8e7SGabor KovesdanOtherwise,
211ad30f8e7SGabor Kovesdan.Fn iconv_open_into
212ad30f8e7SGabor Kovesdanreturns \-1, and sets errno to indicate the error.
213ad30f8e7SGabor Kovesdan.Pp
214ad30f8e7SGabor KovesdanUpon successful completion of
215ad30f8e7SGabor Kovesdan.Fn iconv_close ,
216ad30f8e7SGabor Kovesdanit returns 0.
217ad30f8e7SGabor KovesdanOtherwise,
218ad30f8e7SGabor Kovesdan.Fn iconv_close
219ad30f8e7SGabor Kovesdanreturns \-1 and sets errno to indicate the error.
220ad30f8e7SGabor Kovesdan.Pp
221ad30f8e7SGabor KovesdanUpon successful completion of
222ad30f8e7SGabor Kovesdan.Fn iconv ,
223ad30f8e7SGabor Kovesdanit returns the number of
224ad30f8e7SGabor Kovesdan.Dq invalid
225ad30f8e7SGabor Kovesdanconversions.
226ad30f8e7SGabor KovesdanOtherwise,
227ad30f8e7SGabor Kovesdan.Fn iconv
228ad30f8e7SGabor Kovesdanreturns (size_t)\-1 and sets errno to indicate the error.
229ad30f8e7SGabor Kovesdan.Sh ERRORS
230ad30f8e7SGabor KovesdanThe
231ad30f8e7SGabor Kovesdan.Fn iconv_open
232ad30f8e7SGabor Kovesdanfunction may cause an error in the following cases:
233ad30f8e7SGabor Kovesdan.Bl -tag -width Er
234ad30f8e7SGabor Kovesdan.It Bq Er ENOMEM
235ad30f8e7SGabor KovesdanMemory is exhausted.
236ad30f8e7SGabor Kovesdan.It Bq Er EINVAL
237ad30f8e7SGabor KovesdanThere is no converter specified by
238ad30f8e7SGabor Kovesdan.Fa srcname
239ad30f8e7SGabor Kovesdanand
240ad30f8e7SGabor Kovesdan.Fa dstname .
241ad30f8e7SGabor Kovesdan.El
242ad30f8e7SGabor KovesdanThe
243ad30f8e7SGabor Kovesdan.Fn iconv_open_into
244ad30f8e7SGabor Kovesdanfunction may cause an error in the following cases:
245ad30f8e7SGabor Kovesdan.Bl -tag -width Er
246ad30f8e7SGabor Kovesdan.It Bq Er EINVAL
247ad30f8e7SGabor KovesdanThere is no converter specified by
248ad30f8e7SGabor Kovesdan.Fa srcname
249ad30f8e7SGabor Kovesdanand
250ad30f8e7SGabor Kovesdan.Fa dstname .
251ad30f8e7SGabor Kovesdan.El
252ad30f8e7SGabor Kovesdan.Pp
253ad30f8e7SGabor KovesdanThe
254ad30f8e7SGabor Kovesdan.Fn iconv_close
255ad30f8e7SGabor Kovesdanfunction may cause an error in the following case:
256ad30f8e7SGabor Kovesdan.Bl -tag -width Er
257ad30f8e7SGabor Kovesdan.It Bq Er EBADF
258ad30f8e7SGabor KovesdanThe conversion descriptor specified by
259ad30f8e7SGabor Kovesdan.Fa cd
260ad30f8e7SGabor Kovesdanis invalid.
261ad30f8e7SGabor Kovesdan.El
262ad30f8e7SGabor Kovesdan.Pp
263ad30f8e7SGabor KovesdanThe
264ad30f8e7SGabor Kovesdan.Fn iconv
265ad30f8e7SGabor Kovesdanfunction may cause an error in the following cases:
266ad30f8e7SGabor Kovesdan.Bl -tag -width Er
267ad30f8e7SGabor Kovesdan.It Bq Er EBADF
268ad30f8e7SGabor KovesdanThe conversion descriptor specified by
269ad30f8e7SGabor Kovesdan.Fa cd
270ad30f8e7SGabor Kovesdanis invalid.
271ad30f8e7SGabor Kovesdan.It Bq Er EILSEQ
272ad30f8e7SGabor KovesdanThe string pointed to by
273ad30f8e7SGabor Kovesdan.Fa *src
274ad30f8e7SGabor Kovesdancontains a byte sequence which does not describe a valid character of
275ad30f8e7SGabor Kovesdanthe source codeset.
276ad30f8e7SGabor Kovesdan.It Bq Er E2BIG
277ad30f8e7SGabor KovesdanThe output buffer pointed to by
278ad30f8e7SGabor Kovesdan.Fa *dst
279ad30f8e7SGabor Kovesdanis too small to store the result string.
280ad30f8e7SGabor Kovesdan.It Bq Er EINVAL
281ad30f8e7SGabor KovesdanThe string pointed to by
282ad30f8e7SGabor Kovesdan.Fa *src
283ad30f8e7SGabor Kovesdanterminates with an incomplete character or shift sequence.
284ad30f8e7SGabor Kovesdan.El
285ad30f8e7SGabor Kovesdan.Sh SEE ALSO
286ad30f8e7SGabor Kovesdan.Xr iconv 1 ,
287*9c0b8e48SJohn-Mark Gurney.Xr __iconv_get_list 3 ,
288*9c0b8e48SJohn-Mark Gurney.Xr iconv_canonicalize 3 ,
289*9c0b8e48SJohn-Mark Gurney.Xr iconvctl 3 ,
290*9c0b8e48SJohn-Mark Gurney.Xr iconvlist 3 ,
291ad30f8e7SGabor Kovesdan.Xr mkcsmapper 1 ,
292ad30f8e7SGabor Kovesdan.Xr mkesdb 1
293ad30f8e7SGabor Kovesdan.Sh STANDARDS
294ad30f8e7SGabor KovesdanThe
295ad30f8e7SGabor Kovesdan.Fn iconv_open ,
296ad30f8e7SGabor Kovesdan.Fn iconv_close ,
297ad30f8e7SGabor Kovesdanand
298ad30f8e7SGabor Kovesdan.Fn iconv
299ad30f8e7SGabor Kovesdanfunctions conform to
300ad30f8e7SGabor Kovesdan.St -p1003.1-2008 .
301ad30f8e7SGabor Kovesdan.Pp
302ad30f8e7SGabor KovesdanThe
303ad30f8e7SGabor Kovesdan.Fn iconv_open_into
304ad30f8e7SGabor Kovesdanfunction is a GNU-specific extension and it is not part of any standard,
305ad30f8e7SGabor Kovesdanthus its use may break portability.
306ad30f8e7SGabor KovesdanThe
307ad30f8e7SGabor Kovesdan.Fn __iconv
308ad30f8e7SGabor Kovesdanfunction is an own extension and it is not part of any standard,
309ad30f8e7SGabor Kovesdanthus its use may break portability.
310