11f608a29SJohn Marino.\" $FreeBSD: head/lib/libc/iconv/iconv.3 281550 2015-04-15 09:09:20Z tijl $ 20d5acd74SJohn Marino.\" $NetBSD: iconv.3,v 1.12 2004/08/02 13:38:21 tshiozak Exp $ 32180e8afSJoerg Sonnenberger.\" 42180e8afSJoerg Sonnenberger.\" Copyright (c) 2003 Citrus Project, 50d5acd74SJohn Marino.\" Copyright (c) 2009, 2010 Gabor Kovesdan <gabor@FreeBSD.org>, 62180e8afSJoerg Sonnenberger.\" All rights reserved. 72180e8afSJoerg Sonnenberger.\" 82180e8afSJoerg Sonnenberger.\" Redistribution and use in source and binary forms, with or without 92180e8afSJoerg Sonnenberger.\" modification, are permitted provided that the following conditions 102180e8afSJoerg Sonnenberger.\" are met: 112180e8afSJoerg Sonnenberger.\" 1. Redistributions of source code must retain the above copyright 122180e8afSJoerg Sonnenberger.\" notice, this list of conditions and the following disclaimer. 132180e8afSJoerg Sonnenberger.\" 2. Redistributions in binary form must reproduce the above copyright 142180e8afSJoerg Sonnenberger.\" notice, this list of conditions and the following disclaimer in the 152180e8afSJoerg Sonnenberger.\" documentation and/or other materials provided with the distribution. 162180e8afSJoerg Sonnenberger.\" 172180e8afSJoerg Sonnenberger.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 182180e8afSJoerg Sonnenberger.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 192180e8afSJoerg Sonnenberger.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 202180e8afSJoerg Sonnenberger.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 212180e8afSJoerg Sonnenberger.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 222180e8afSJoerg Sonnenberger.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 232180e8afSJoerg Sonnenberger.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 242180e8afSJoerg Sonnenberger.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 252180e8afSJoerg Sonnenberger.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 262180e8afSJoerg Sonnenberger.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 272180e8afSJoerg Sonnenberger.\" SUCH DAMAGE. 282180e8afSJoerg Sonnenberger.\" 291f608a29SJohn Marino.Dd August 4, 2014 302180e8afSJoerg Sonnenberger.Dt ICONV 3 312180e8afSJoerg Sonnenberger.Os 322180e8afSJoerg Sonnenberger.Sh NAME 332180e8afSJoerg Sonnenberger.Nm iconv_open , 340d5acd74SJohn Marino.Nm iconv_open_into , 352180e8afSJoerg Sonnenberger.Nm iconv_close , 362180e8afSJoerg Sonnenberger.Nm iconv 372180e8afSJoerg Sonnenberger.Nd codeset conversion functions 382180e8afSJoerg Sonnenberger.Sh LIBRARY 392180e8afSJoerg Sonnenberger.Lb libc 402180e8afSJoerg Sonnenberger.Sh SYNOPSIS 412180e8afSJoerg Sonnenberger.In iconv.h 422180e8afSJoerg Sonnenberger.Ft iconv_t 432180e8afSJoerg Sonnenberger.Fn iconv_open "const char *dstname" "const char *srcname" 442180e8afSJoerg Sonnenberger.Ft int 450d5acd74SJohn Marino.Fn iconv_open_into "const char *dstname" "const char *srcname" "iconv_allocation_t *ptr" 460d5acd74SJohn Marino.Ft int 472180e8afSJoerg Sonnenberger.Fn iconv_close "iconv_t cd" 482180e8afSJoerg Sonnenberger.Ft size_t 492180e8afSJoerg Sonnenberger.Fn iconv "iconv_t cd" "char ** restrict src" "size_t * restrict srcleft" "char ** restrict dst" "size_t * restrict dstleft" 500d5acd74SJohn Marino.Ft size_t 511f608a29SJohn Marino.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" 522180e8afSJoerg Sonnenberger.Sh DESCRIPTION 532180e8afSJoerg SonnenbergerThe 542180e8afSJoerg Sonnenberger.Fn iconv_open 552180e8afSJoerg Sonnenbergerfunction opens a converter from the codeset 562180e8afSJoerg Sonnenberger.Fa srcname 572180e8afSJoerg Sonnenbergerto the codeset 582180e8afSJoerg Sonnenberger.Fa dstname 592180e8afSJoerg Sonnenbergerand returns its descriptor. 600d5acd74SJohn MarinoThe arguments 610d5acd74SJohn Marino.Fa srcname 620d5acd74SJohn Marinoand 630d5acd74SJohn Marino.Fa dstname 640d5acd74SJohn Marinoaccept "" and "char", which refer to the current locale encoding. 650d5acd74SJohn Marino.Pp 660d5acd74SJohn MarinoThe 670d5acd74SJohn Marino.Fn iconv_open_into 680d5acd74SJohn Marinocreates a conversion descriptor on a preallocated space. 690d5acd74SJohn MarinoThe 700d5acd74SJohn Marino.Ft iconv_allocation_t 710d5acd74SJohn Marinois used as a spaceholder type when allocating such space. 720d5acd74SJohn MarinoThe 730d5acd74SJohn Marino.Fa dstname 740d5acd74SJohn Marinoand 750d5acd74SJohn Marino.Fa srcname 760d5acd74SJohn Marinoarguments are the same as in the case of 770d5acd74SJohn Marino.Fn iconv_open . 780d5acd74SJohn MarinoThe 790d5acd74SJohn Marino.Fa ptr 800d5acd74SJohn Marinoargument is a pointer of 810d5acd74SJohn Marino.Ft iconv_allocation_t 820d5acd74SJohn Marinoto the preallocated space. 832180e8afSJoerg Sonnenberger.Pp 842180e8afSJoerg SonnenbergerThe 852180e8afSJoerg Sonnenberger.Fn iconv_close 862180e8afSJoerg Sonnenbergerfunction closes the specified converter 872180e8afSJoerg Sonnenberger.Fa cd . 882180e8afSJoerg Sonnenberger.Pp 892180e8afSJoerg SonnenbergerThe 902180e8afSJoerg Sonnenberger.Fn iconv 912180e8afSJoerg Sonnenbergerfunction converts the string in the buffer 922180e8afSJoerg Sonnenberger.Fa *src 932180e8afSJoerg Sonnenbergerof length 942180e8afSJoerg Sonnenberger.Fa *srcleft 952180e8afSJoerg Sonnenbergerbytes and stores the converted string in the buffer 962180e8afSJoerg Sonnenberger.Fa *dst 972180e8afSJoerg Sonnenbergerof size 982180e8afSJoerg Sonnenberger.Fa *dstleft 992180e8afSJoerg Sonnenbergerbytes. 1002180e8afSJoerg SonnenbergerAfter calling 1012180e8afSJoerg Sonnenberger.Fn iconv , 1022180e8afSJoerg Sonnenbergerthe values pointed to by 1032180e8afSJoerg Sonnenberger.Fa src , 1042180e8afSJoerg Sonnenberger.Fa srcleft , 1052180e8afSJoerg Sonnenberger.Fa dst , 1062180e8afSJoerg Sonnenbergerand 1072180e8afSJoerg Sonnenberger.Fa dstleft 1082180e8afSJoerg Sonnenbergerare updated as follows: 1092180e8afSJoerg Sonnenberger.Bl -tag -width 01234567 1102180e8afSJoerg Sonnenberger.It *src 1112180e8afSJoerg SonnenbergerPointer to the byte just after the last character fetched. 1122180e8afSJoerg Sonnenberger.It *srcleft 1132180e8afSJoerg SonnenbergerNumber of remaining bytes in the source buffer. 1142180e8afSJoerg Sonnenberger.It *dst 1152180e8afSJoerg SonnenbergerPointer to the byte just after the last character stored. 1162180e8afSJoerg Sonnenberger.It *dstleft 1172180e8afSJoerg SonnenbergerNumber of remainder bytes in the destination buffer. 1182180e8afSJoerg Sonnenberger.El 1192180e8afSJoerg Sonnenberger.Pp 1202180e8afSJoerg SonnenbergerIf the string pointed to by 1212180e8afSJoerg Sonnenberger.Fa *src 1222180e8afSJoerg Sonnenbergercontains a byte sequence which is not a valid character in the source 1232180e8afSJoerg Sonnenbergercodeset, the conversion stops just after the last successful conversion. 1242180e8afSJoerg SonnenbergerIf the output buffer is too small to store the converted 1252180e8afSJoerg Sonnenbergercharacter, the conversion also stops in the same way. 1262180e8afSJoerg SonnenbergerIn these cases, the values pointed to by 1272180e8afSJoerg Sonnenberger.Fa src , 1282180e8afSJoerg Sonnenberger.Fa srcleft , 1292180e8afSJoerg Sonnenberger.Fa dst , 1302180e8afSJoerg Sonnenbergerand 1312180e8afSJoerg Sonnenberger.Fa dstleft 1322180e8afSJoerg Sonnenbergerare updated to the state just after the last successful conversion. 1332180e8afSJoerg Sonnenberger.Pp 1342180e8afSJoerg SonnenbergerIf the string pointed to by 1352180e8afSJoerg Sonnenberger.Fa *src 1362180e8afSJoerg Sonnenbergercontains a character which is valid under the source codeset but 1372180e8afSJoerg Sonnenbergercan not be converted to the destination codeset, 1382180e8afSJoerg Sonnenbergerthe character is replaced by an 1392180e8afSJoerg Sonnenberger.Dq invalid character 1402180e8afSJoerg Sonnenbergerwhich depends on the destination codeset, e.g., 1412180e8afSJoerg Sonnenberger.Sq \&? , 1422180e8afSJoerg Sonnenbergerand the conversion is continued. 1432180e8afSJoerg Sonnenberger.Fn iconv 1442180e8afSJoerg Sonnenbergerreturns the number of such 1452180e8afSJoerg Sonnenberger.Dq invalid conversions . 1462180e8afSJoerg Sonnenberger.Pp 1472180e8afSJoerg SonnenbergerThere are two special cases of 1482180e8afSJoerg Sonnenberger.Fn iconv : 1492180e8afSJoerg Sonnenberger.Bl -tag -width 0123 1502180e8afSJoerg Sonnenberger.It "src == NULL || *src == NULL" 1512180e8afSJoerg SonnenbergerIf the source and/or destination codesets are stateful, 1522180e8afSJoerg Sonnenberger.Fn iconv 1532180e8afSJoerg Sonnenbergerplaces these into their initial state. 1542180e8afSJoerg Sonnenberger.Pp 1552180e8afSJoerg SonnenbergerIf both 1562180e8afSJoerg Sonnenberger.Fa dst 1572180e8afSJoerg Sonnenbergerand 1582180e8afSJoerg Sonnenberger.Fa *dst 1592180e8afSJoerg Sonnenbergerare 1602180e8afSJoerg Sonnenberger.No non- Ns Dv NULL , 1612180e8afSJoerg Sonnenberger.Fn iconv 1622180e8afSJoerg Sonnenbergerstores the shift sequence for the destination switching to the initial state 1632180e8afSJoerg Sonnenbergerin the buffer pointed to by 1642180e8afSJoerg Sonnenberger.Fa *dst . 1652180e8afSJoerg SonnenbergerThe buffer size is specified by the value pointed to by 1662180e8afSJoerg Sonnenberger.Fa dstleft 1672180e8afSJoerg Sonnenbergeras above. 1682180e8afSJoerg Sonnenberger.Fn iconv 1692180e8afSJoerg Sonnenbergerwill fail if the buffer is too small to store the shift sequence. 1702180e8afSJoerg Sonnenberger.Pp 1712180e8afSJoerg SonnenbergerOn the other hand, 1722180e8afSJoerg Sonnenberger.Fa dst 1732180e8afSJoerg Sonnenbergeror 1742180e8afSJoerg Sonnenberger.Fa *dst 1752180e8afSJoerg Sonnenbergermay be 1762180e8afSJoerg Sonnenberger.Dv NULL . 1772180e8afSJoerg SonnenbergerIn this case, the shift sequence for the destination switching 1782180e8afSJoerg Sonnenbergerto the initial state is discarded. 1792180e8afSJoerg Sonnenberger.El 1808d975f05SSascha Wildner.Pp 1810d5acd74SJohn MarinoThe 1820d5acd74SJohn Marino.Fn __iconv 1830d5acd74SJohn Marinofunction works just like 1840d5acd74SJohn Marino.Fn iconv 1850d5acd74SJohn Marinobut if 1860d5acd74SJohn Marino.Fn iconv 1870d5acd74SJohn Marinofails, the invalid character count is lost there. 1880d5acd74SJohn MarinoThis is a not bug rather a limitation of 1890d5acd74SJohn Marino.St -p1003.1-2008 , 1900d5acd74SJohn Marinoso 1910d5acd74SJohn Marino.Fn __iconv 1920d5acd74SJohn Marinois provided as an alternative but non-standard interface. 1930d5acd74SJohn MarinoIt also has a flags argument, where currently the following 1940d5acd74SJohn Marinoflags can be passed: 1950d5acd74SJohn Marino.Bl -tag -width 0123 196*9495a4fbSSascha Wildner.It Dv __ICONV_F_HIDE_INVALID 1970d5acd74SJohn MarinoSkip invalid characters, instead of returning with an error. 1980d5acd74SJohn Marino.El 1992180e8afSJoerg Sonnenberger.Sh RETURN VALUES 2002180e8afSJoerg SonnenbergerUpon successful completion of 2012180e8afSJoerg Sonnenberger.Fn iconv_open , 2022180e8afSJoerg Sonnenbergerit returns a conversion descriptor. 2032180e8afSJoerg SonnenbergerOtherwise, 2042180e8afSJoerg Sonnenberger.Fn iconv_open 2050d5acd74SJohn Marinoreturns (iconv_t)\-1 and sets errno to indicate the error. 2060d5acd74SJohn Marino.Pp 2070d5acd74SJohn MarinoUpon successful completion of 2080d5acd74SJohn Marino.Fn iconv_open_into , 2090d5acd74SJohn Marinoit returns 0. 2100d5acd74SJohn MarinoOtherwise, 2110d5acd74SJohn Marino.Fn iconv_open_into 2120d5acd74SJohn Marinoreturns \-1, and sets errno to indicate the error. 2132180e8afSJoerg Sonnenberger.Pp 2142180e8afSJoerg SonnenbergerUpon successful completion of 2152180e8afSJoerg Sonnenberger.Fn iconv_close , 2162180e8afSJoerg Sonnenbergerit returns 0. 2172180e8afSJoerg SonnenbergerOtherwise, 2182180e8afSJoerg Sonnenberger.Fn iconv_close 2190d5acd74SJohn Marinoreturns \-1 and sets errno to indicate the error. 2202180e8afSJoerg Sonnenberger.Pp 2212180e8afSJoerg SonnenbergerUpon successful completion of 2222180e8afSJoerg Sonnenberger.Fn iconv , 2232180e8afSJoerg Sonnenbergerit returns the number of 2242180e8afSJoerg Sonnenberger.Dq invalid 2252180e8afSJoerg Sonnenbergerconversions. 2262180e8afSJoerg SonnenbergerOtherwise, 2272180e8afSJoerg Sonnenberger.Fn iconv 2280d5acd74SJohn Marinoreturns (size_t)\-1 and sets errno to indicate the error. 2292180e8afSJoerg Sonnenberger.Sh ERRORS 2302180e8afSJoerg SonnenbergerThe 2312180e8afSJoerg Sonnenberger.Fn iconv_open 2322180e8afSJoerg Sonnenbergerfunction may cause an error in the following cases: 2332180e8afSJoerg Sonnenberger.Bl -tag -width Er 2342180e8afSJoerg Sonnenberger.It Bq Er ENOMEM 2352180e8afSJoerg SonnenbergerMemory is exhausted. 2362180e8afSJoerg Sonnenberger.It Bq Er EINVAL 2372180e8afSJoerg SonnenbergerThere is no converter specified by 2382180e8afSJoerg Sonnenberger.Fa srcname 2392180e8afSJoerg Sonnenbergerand 2402180e8afSJoerg Sonnenberger.Fa dstname . 2412180e8afSJoerg Sonnenberger.El 2420d5acd74SJohn MarinoThe 2430d5acd74SJohn Marino.Fn iconv_open_into 2440d5acd74SJohn Marinofunction may cause an error in the following cases: 2450d5acd74SJohn Marino.Bl -tag -width Er 2460d5acd74SJohn Marino.It Bq Er EINVAL 2470d5acd74SJohn MarinoThere is no converter specified by 2480d5acd74SJohn Marino.Fa srcname 2490d5acd74SJohn Marinoand 2500d5acd74SJohn Marino.Fa dstname . 2510d5acd74SJohn Marino.El 2522180e8afSJoerg Sonnenberger.Pp 2532180e8afSJoerg SonnenbergerThe 2542180e8afSJoerg Sonnenberger.Fn iconv_close 2552180e8afSJoerg Sonnenbergerfunction may cause an error in the following case: 2562180e8afSJoerg Sonnenberger.Bl -tag -width Er 2572180e8afSJoerg Sonnenberger.It Bq Er EBADF 2582180e8afSJoerg SonnenbergerThe conversion descriptor specified by 2592180e8afSJoerg Sonnenberger.Fa cd 2602180e8afSJoerg Sonnenbergeris invalid. 2612180e8afSJoerg Sonnenberger.El 2622180e8afSJoerg Sonnenberger.Pp 2632180e8afSJoerg SonnenbergerThe 2642180e8afSJoerg Sonnenberger.Fn iconv 2652180e8afSJoerg Sonnenbergerfunction may cause an error in the following cases: 2662180e8afSJoerg Sonnenberger.Bl -tag -width Er 2672180e8afSJoerg Sonnenberger.It Bq Er EBADF 2682180e8afSJoerg SonnenbergerThe conversion descriptor specified by 2692180e8afSJoerg Sonnenberger.Fa cd 2702180e8afSJoerg Sonnenbergeris invalid. 2712180e8afSJoerg Sonnenberger.It Bq Er EILSEQ 2722180e8afSJoerg SonnenbergerThe string pointed to by 2732180e8afSJoerg Sonnenberger.Fa *src 2742180e8afSJoerg Sonnenbergercontains a byte sequence which does not describe a valid character of 2752180e8afSJoerg Sonnenbergerthe source codeset. 2762180e8afSJoerg Sonnenberger.It Bq Er E2BIG 2772180e8afSJoerg SonnenbergerThe output buffer pointed to by 2782180e8afSJoerg Sonnenberger.Fa *dst 2792180e8afSJoerg Sonnenbergeris too small to store the result string. 2802180e8afSJoerg Sonnenberger.It Bq Er EINVAL 2812180e8afSJoerg SonnenbergerThe string pointed to by 2822180e8afSJoerg Sonnenberger.Fa *src 2832180e8afSJoerg Sonnenbergerterminates with an incomplete character or shift sequence. 2842180e8afSJoerg Sonnenberger.El 2852180e8afSJoerg Sonnenberger.Sh SEE ALSO 2860d5acd74SJohn Marino.Xr iconv 1 , 2870d5acd74SJohn Marino.Xr mkcsmapper 1 , 2881f608a29SJohn Marino.Xr mkesdb 1 , 2891f608a29SJohn Marino.Xr __iconv_get_list 3 , 2901f608a29SJohn Marino.Xr iconv_canonicalize 3 , 2911f608a29SJohn Marino.Xr iconvctl 3 , 2921f608a29SJohn Marino.Xr iconvlist 3 2932180e8afSJoerg Sonnenberger.Sh STANDARDS 2940d5acd74SJohn MarinoThe 2952180e8afSJoerg Sonnenberger.Fn iconv_open , 2962180e8afSJoerg Sonnenberger.Fn iconv_close , 2972180e8afSJoerg Sonnenbergerand 2982180e8afSJoerg Sonnenberger.Fn iconv 2990d5acd74SJohn Marinofunctions conform to 3000d5acd74SJohn Marino.St -p1003.1-2008 . 3010d5acd74SJohn Marino.Pp 3020d5acd74SJohn MarinoThe 3030d5acd74SJohn Marino.Fn iconv_open_into 3040d5acd74SJohn Marinofunction is a GNU-specific extension and it is not part of any standard, 3050d5acd74SJohn Marinothus its use may break portability. 3060d5acd74SJohn MarinoThe 3070d5acd74SJohn Marino.Fn __iconv 3080d5acd74SJohn Marinofunction is an own extension and it is not part of any standard, 3090d5acd74SJohn Marinothus its use may break portability. 310