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