1*77a1ad5fSkamil.\" $NetBSD: iconv.3,v 1.24 2019/10/24 18:17:59 kamil Exp $ 2a781221fStshiozak.\" 3a781221fStshiozak.\" Copyright (c)2003 Citrus Project, 4a781221fStshiozak.\" All rights reserved. 5a781221fStshiozak.\" 6a781221fStshiozak.\" Redistribution and use in source and binary forms, with or without 7a781221fStshiozak.\" modification, are permitted provided that the following conditions 8a781221fStshiozak.\" are met: 9a781221fStshiozak.\" 1. Redistributions of source code must retain the above copyright 10a781221fStshiozak.\" notice, this list of conditions and the following disclaimer. 11a781221fStshiozak.\" 2. Redistributions in binary form must reproduce the above copyright 12a781221fStshiozak.\" notice, this list of conditions and the following disclaimer in the 13a781221fStshiozak.\" documentation and/or other materials provided with the distribution. 14a781221fStshiozak.\" 15a781221fStshiozak.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16a781221fStshiozak.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17a781221fStshiozak.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18a781221fStshiozak.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19a781221fStshiozak.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20a781221fStshiozak.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21a781221fStshiozak.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22a781221fStshiozak.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23a781221fStshiozak.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24a781221fStshiozak.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25a781221fStshiozak.\" SUCH DAMAGE. 26a781221fStshiozak.\" 27*77a1ad5fSkamil.Dd October 24, 2019 285e93a9d9Swiz.Dt ICONV 3 29a781221fStshiozak.Os 30a781221fStshiozak.\" ---------------------------------------------------------------------- 31a781221fStshiozak.Sh NAME 32a781221fStshiozak.Nm iconv_open , 33a781221fStshiozak.Nm iconv_close , 34a781221fStshiozak.Nm iconv 35a781221fStshiozak.Nd codeset conversion functions 36a781221fStshiozak.\" ---------------------------------------------------------------------- 37a781221fStshiozak.Sh LIBRARY 38a781221fStshiozak.Lb libc 39a781221fStshiozak.\" ---------------------------------------------------------------------- 40a781221fStshiozak.Sh SYNOPSIS 41a781221fStshiozak.In iconv.h 42a781221fStshiozak.Ft iconv_t 43a781221fStshiozak.Fn iconv_open "const char *dstname" "const char *srcname" 44a781221fStshiozak.Ft int 45a781221fStshiozak.Fn iconv_close "iconv_t cd" 46a781221fStshiozak.Ft size_t 47*77a1ad5fSkamil.Fn iconv "iconv_t cd" "char ** restrict src" "size_t * restrict srcleft" "char ** restrict dst" "size_t * restrict dstleft" 48a781221fStshiozak.\" ---------------------------------------------------------------------- 49a781221fStshiozak.Sh DESCRIPTION 50a781221fStshiozakThe 51a781221fStshiozak.Fn iconv_open 52a781221fStshiozakfunction opens a converter from the codeset 53a781221fStshiozak.Fa srcname 54a781221fStshiozakto the codeset 55a781221fStshiozak.Fa dstname 56a781221fStshiozakand returns its descriptor. 57a781221fStshiozak.Pp 58a781221fStshiozakThe 59a781221fStshiozak.Fn iconv_close 605e93a9d9Swizfunction closes the specified converter 61a781221fStshiozak.Fa cd . 62a781221fStshiozak.Pp 63a781221fStshiozakThe 64a781221fStshiozak.Fn iconv 655e93a9d9Swizfunction converts the string in the buffer 66a781221fStshiozak.Fa *src 675e93a9d9Swizof length 68a781221fStshiozak.Fa *srcleft 695e93a9d9Swizbytes and stores the converted string in the buffer 70a781221fStshiozak.Fa *dst 715e93a9d9Swizof size 72a781221fStshiozak.Fa *dstleft 73a781221fStshiozakbytes. 74a781221fStshiozakAfter calling 75a781221fStshiozak.Fn iconv , 765e93a9d9Swizthe values pointed to by 77a781221fStshiozak.Fa src , 78a781221fStshiozak.Fa srcleft , 795e93a9d9Swiz.Fa dst , 80a781221fStshiozakand 81a781221fStshiozak.Fa dstleft 825e93a9d9Swizare updated as follows: 8312456d30Sjruoho.Bl -tag -width 01234567 -offset indent 8412456d30Sjruoho.It Fa *src 85a781221fStshiozakPointer to the byte just after the last character fetched. 8612456d30Sjruoho.It Fa *srcleft 875e93a9d9SwizNumber of remaining bytes in the source buffer. 8812456d30Sjruoho.It Fa *dst 89a781221fStshiozakPointer to the byte just after the last character stored. 9012456d30Sjruoho.It Fa *dstleft 915e93a9d9SwizNumber of remainder bytes in the destination buffer. 92a781221fStshiozak.El 93a781221fStshiozak.Pp 945e93a9d9SwizIf the string pointed to by 95a781221fStshiozak.Fa *src 965e93a9d9Swizcontains a byte sequence which is not a valid character in the source 97a781221fStshiozakcodeset, the conversion stops just after the last successful conversion. 985e93a9d9SwizIf the output buffer is too small to store the converted 99a781221fStshiozakcharacter, the conversion also stops in the same way. 1005e93a9d9SwizIn these cases, the values pointed to by 101a781221fStshiozak.Fa src , 102a781221fStshiozak.Fa srcleft , 1035e93a9d9Swiz.Fa dst , 104a781221fStshiozakand 105a781221fStshiozak.Fa dstleft 1065e93a9d9Swizare updated to the state just after the last successful conversion. 107a781221fStshiozak.Pp 1085e93a9d9SwizIf the string pointed to by 109a781221fStshiozak.Fa *src 11036f4f7f5Swizcontains a character which is valid under the source codeset but 111a781221fStshiozakcan not be converted to the destination codeset, 1125e93a9d9Swizthe character is replaced by an 1135e93a9d9Swiz.Dq invalid character 1145e93a9d9Swizwhich depends on the destination codeset, e.g., 1155e93a9d9Swiz.Sq \&? , 1165e93a9d9Swizand the conversion is continued. 117a781221fStshiozak.Fn iconv 1185e93a9d9Swizreturns the number of such 1195e93a9d9Swiz.Dq invalid conversions . 120a781221fStshiozak.Pp 1217c323d88SyamtIf 1227c323d88Syamt.Fa src 1237c323d88Syamtor 1247c323d88Syamt.Fa *src 1257c323d88Syamtis 1267c323d88Syamt.Dv NULL 1277c323d88Syamtand the source and/or destination codesets are stateful, 128cf33db0fStshiozak.Fn iconv 129cf33db0fStshiozakplaces these into their initial state. 13012456d30Sjruoho.Bl -enum -offset indent 13112456d30Sjruoho.It 132cf33db0fStshiozakIf both 133cf33db0fStshiozak.Fa dst 134cf33db0fStshiozakand 135cf33db0fStshiozak.Fa *dst 136f88c1938Swizare 137f88c1938Swiz.No non- Ns Dv NULL , 138cf33db0fStshiozak.Fn iconv 139cf33db0fStshiozakstores the shift sequence for the destination switching to the initial state 140cf33db0fStshiozakin the buffer pointed to by 141a781221fStshiozak.Fa *dst . 14294474093SwizThe buffer size is specified by the value pointed to by 1436f555a80Stshiozak.Fa dstleft 14494474093Swizas above. 1456f555a80Stshiozak.Fn iconv 1466f555a80Stshiozakwill fail if the buffer is too small to store the shift sequence. 14712456d30Sjruoho.It 148cf33db0fStshiozakOn the other hand, 149cf33db0fStshiozak.Fa dst 150cf33db0fStshiozakor 151cf33db0fStshiozak.Fa *dst 152f88c1938Swizmay be 153f88c1938Swiz.Dv NULL . 154f88c1938SwizIn this case, the shift sequence for the destination switching 155cf33db0fStshiozakto the initial state is discarded. 156a781221fStshiozak.El 157a781221fStshiozak.\" ---------------------------------------------------------------------- 158a781221fStshiozak.Sh RETURN VALUES 1595e93a9d9SwizUpon successful completion of 160a781221fStshiozak.Fn iconv_open , 1615e93a9d9Swizit returns a conversion descriptor. 1625e93a9d9SwizOtherwise, 163a781221fStshiozak.Fn iconv_open 16412456d30Sjruohoreturns (iconv_t)\-1 and sets 16512456d30Sjruoho.Va errno 16612456d30Sjruohoto indicate the error. 167a781221fStshiozak.Pp 1685e93a9d9SwizUpon successful completion of 169a781221fStshiozak.Fn iconv_close , 170a781221fStshiozakit returns 0. 171a781221fStshiozakOtherwise, 172a781221fStshiozak.Fn iconv_close 1735e93a9d9Swizreturns \-1 and sets errno to indicate the error. 174a781221fStshiozak.Pp 1755e93a9d9SwizUpon successful completion of 176a781221fStshiozak.Fn iconv , 1775e93a9d9Swizit returns the number of 1785e93a9d9Swiz.Dq invalid 1795e93a9d9Swizconversions. 180a781221fStshiozakOtherwise, 181a781221fStshiozak.Fn iconv 1825e93a9d9Swizreturns (size_t)\-1 and sets errno to indicate the error. 183a781221fStshiozak.\" ---------------------------------------------------------------------- 184a781221fStshiozak.Sh ERRORS 185a781221fStshiozakThe 186a781221fStshiozak.Fn iconv_open 18736f4f7f5Swizfunction may cause an error in the following cases: 188a781221fStshiozak.Bl -tag -width Er 189a781221fStshiozak.It Bq Er EINVAL 190a781221fStshiozakThere is no converter specified by 191a781221fStshiozak.Fa srcname 192a781221fStshiozakand 193a781221fStshiozak.Fa dstname . 194c4519650Swiz.It Bq Er ENOMEM 195c4519650SwizMemory is exhausted. 196a781221fStshiozak.El 197a781221fStshiozak.Pp 198a781221fStshiozakThe 199a781221fStshiozak.Fn iconv_close 20036f4f7f5Swizfunction may cause an error in the following case: 201a781221fStshiozak.Bl -tag -width Er 202a781221fStshiozak.It Bq Er EBADF 203a781221fStshiozakThe conversion descriptor specified by 204a781221fStshiozak.Fa cd 205a781221fStshiozakis invalid. 206a781221fStshiozak.El 207a781221fStshiozak.Pp 208a781221fStshiozakThe 209a781221fStshiozak.Fn iconv 21036f4f7f5Swizfunction may cause an error in the following cases: 211a781221fStshiozak.Bl -tag -width Er 212c4519650Swiz.It Bq Er E2BIG 213c4519650SwizThe output buffer pointed to by 214c4519650Swiz.Fa *dst 215c4519650Swizis too small to store the result string. 216a781221fStshiozak.It Bq Er EBADF 217a781221fStshiozakThe conversion descriptor specified by 218a781221fStshiozak.Fa cd 219a781221fStshiozakis invalid. 220a781221fStshiozak.It Bq Er EILSEQ 2215e93a9d9SwizThe string pointed to by 222a781221fStshiozak.Fa *src 2235e93a9d9Swizcontains a byte sequence which does not describe a valid character of 224a781221fStshiozakthe source codeset. 225a781221fStshiozak.It Bq Er EINVAL 2265e93a9d9SwizThe string pointed to by 227a781221fStshiozak.Fa *src 2285e93a9d9Swizterminates with an incomplete character or shift sequence. 229a781221fStshiozak.El 230a781221fStshiozak.\" ---------------------------------------------------------------------- 231a781221fStshiozak.Sh SEE ALSO 232a781221fStshiozak.Xr iconv 1 233a781221fStshiozak.\" ---------------------------------------------------------------------- 234a781221fStshiozak.Sh STANDARDS 235a781221fStshiozak.Fn iconv_open , 2365e93a9d9Swiz.Fn iconv_close , 237a781221fStshiozakand 238a781221fStshiozak.Fn iconv 2399da71ac3Swizconform to 240a781221fStshiozak.St -p1003.1-2001 . 2411decb32eSchristos.Pp 2422f4276caSdhollandHistorically, the definition of 2431decb32eSchristos.Ft iconv 2441decb32eSchristoshas not been consistent across operating systems. 2452f4276caSdhollandThis is due to an unfortunate historical mistake, documented in 2462f4276caSdholland.Lk https://www5.opengroup.org/sophocles2/show_mail.tpl?&source=L&listname=austin-group-l&id=7404 "this e-mail". 2472f4276caSdhollandThe standards page for the header file 2482f4276caSdholland.In iconv.h 2492f4276caSdhollanddefined the second argument of 2502f4276caSdholland.Fn iconv 2512f4276caSdhollandas 2522f4276caSdholland.Ft char ** , 2532f4276caSdhollandbut the standards page for the 2542f4276caSdholland.Fn iconv 2552f4276caSdhollandimplementation defined it as 2562f4276caSdholland.Ft const char ** . 2572f4276caSdhollandThe standards committee later chose to change the function definition to 2582f4276caSdhollandfollow the header file definition 2592f4276caSdholland.Pq without const , 2602f4276caSdhollandeven though the version with const is arguably more correct. 2612f4276caSdholland.Nx 262*77a1ad5fSkamilused initially the const form. 2632f4276caSdhollandIt was decided to reject the committee's regression and become 2642f4276caSdholland.Pq technically 2652f4276caSdhollandincompatible. 266*77a1ad5fSkamil.Pp 267*77a1ad5fSkamilThis decision was changed in 268*77a1ad5fSkamil.Nx 10 269*77a1ad5fSkamiland the 270*77a1ad5fSkamil.Fn iconv 271*77a1ad5fSkamilprototype was synchronized with the standard. 2725e93a9d9Swiz.\" ---------------------------------------------------------------------- 2735e93a9d9Swiz.Sh BUGS 2745e93a9d9SwizIf 2755e93a9d9Swiz.Fn iconv 2765e93a9d9Swizis aborted due to the occurrence of some error, 2775e93a9d9Swizthe 2785e93a9d9Swiz.Dq invalid conversion 2795e93a9d9Swizcount mentioned above is unfortunately lost. 280