1*4dc858f2Swiz.\" $NetBSD: mbsrtowcs.3,v 1.15 2024/09/09 18:55:26 wiz Exp $ 28625ada8Stshiozak.\" 38625ada8Stshiozak.\" Copyright (c)2002 Citrus Project, 48625ada8Stshiozak.\" All rights reserved. 58625ada8Stshiozak.\" 68625ada8Stshiozak.\" Redistribution and use in source and binary forms, with or without 78625ada8Stshiozak.\" modification, are permitted provided that the following conditions 88625ada8Stshiozak.\" are met: 98625ada8Stshiozak.\" 1. Redistributions of source code must retain the above copyright 108625ada8Stshiozak.\" notice, this list of conditions and the following disclaimer. 118625ada8Stshiozak.\" 2. Redistributions in binary form must reproduce the above copyright 128625ada8Stshiozak.\" notice, this list of conditions and the following disclaimer in the 138625ada8Stshiozak.\" documentation and/or other materials provided with the distribution. 148625ada8Stshiozak.\" 158625ada8Stshiozak.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 168625ada8Stshiozak.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 178625ada8Stshiozak.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 188625ada8Stshiozak.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 198625ada8Stshiozak.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 208625ada8Stshiozak.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 218625ada8Stshiozak.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 228625ada8Stshiozak.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 238625ada8Stshiozak.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 248625ada8Stshiozak.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 258625ada8Stshiozak.\" SUCH DAMAGE. 268625ada8Stshiozak.\" 27b3c7e95dSriastradh.Dd September 9, 2024 288625ada8Stshiozak.Dt MBSRTOWCS 3 298625ada8Stshiozak.Os 308625ada8Stshiozak.\" ---------------------------------------------------------------------- 318625ada8Stshiozak.Sh NAME 32*4dc858f2Swiz.Nm mbsrtowcs , 33b3c7e95dSriastradh.Nm mbsrntowcs 343d3c5d42Swiz.Nd converts a multibyte character string to a wide-character string \ 358625ada8Stshiozak(restartable) 368625ada8Stshiozak.\" ---------------------------------------------------------------------- 378625ada8Stshiozak.Sh LIBRARY 388625ada8Stshiozak.Lb libc 398625ada8Stshiozak.\" ---------------------------------------------------------------------- 408625ada8Stshiozak.Sh SYNOPSIS 4112d1d194Suwe. 42472351e1Swiz.In wchar.h 4312d1d194Suwe. 448625ada8Stshiozak.Ft size_t 4512d1d194Suwe.Fo mbsrtowcs 4612d1d194Suwe.Fa "wchar_t * restrict pwcs" 4712d1d194Suwe.Fa "const char ** restrict s" 4812d1d194Suwe.Fa "size_t n" 4912d1d194Suwe.Fa "mbstate_t * restrict ps" 5012d1d194Suwe.Fc 5112d1d194Suwe. 5212d1d194Suwe.Ft size_t 5312d1d194Suwe.Fo mbsnrtowcs 5412d1d194Suwe.Fa "wchar_t * restrict pwcs" 5512d1d194Suwe.Fa "const char ** restrict s" 5612d1d194Suwe.Fa "size_t nmc" 5712d1d194Suwe.Fa "size_t n" 5812d1d194Suwe.Fa "mbstate_t * restrict ps" 5912d1d194Suwe.Fc 6012d1d194Suwe. 618625ada8Stshiozak.\" ---------------------------------------------------------------------- 628625ada8Stshiozak.Sh DESCRIPTION 638625ada8StshiozakThe 648625ada8Stshiozak.Fn mbsrtowcs 65b3c7e95dSriastradhfunction converts the multibyte character string indirectly pointed to 66b3c7e95dSriastradhby 678625ada8Stshiozak.Fa s 683d3c5d42Swizto the corresponding wide-character string, and stores it in the 69cef0afe9Swizarray pointed to by 708625ada8Stshiozak.Fa pwcs . 719f64fab4SwizThe conversion stops due to the following reasons: 728625ada8Stshiozak.Bl -bullet 738625ada8Stshiozak.It 74*4dc858f2SwizThe conversion reaches a NUL byte. 75*4dc858f2SwizIn this case, the NUL byte is also converted. 768625ada8Stshiozak.It 778625ada8StshiozakThe 788625ada8Stshiozak.Fn mbsrtowcs 798625ada8Stshiozakhas already stored 808625ada8Stshiozak.Fa n 818625ada8Stshiozakwide characters. 828625ada8Stshiozak.It 838625ada8StshiozakThe conversion encounters an invalid character. 848625ada8Stshiozak.El 858625ada8Stshiozak.Pp 86be85fac5SjmmvEach character will be converted as if 878625ada8Stshiozak.Xr mbrtowc 3 888625ada8Stshiozakis continuously called. 898625ada8Stshiozak.Pp 908625ada8StshiozakAfter conversion, 918625ada8Stshiozakif 928625ada8Stshiozak.Fa pwcs 93*4dc858f2Swizis not a NULL pointer, 94cef0afe9Swizthe pointer object pointed to by 958625ada8Stshiozak.Fa s 96*4dc858f2Swizis a NULL pointer 97*4dc858f2Swiz.Pq if the conversion is stopped due to reaching a NUL byte 9812d1d194Suweor the first byte of the character just after the last character 9912d1d194Suweconverted. 1008625ada8Stshiozak.Pp 1018625ada8StshiozakIf 1028625ada8Stshiozak.Fa pwcs 103*4dc858f2Swizis not a NULL pointer and the conversion is stopped due to reaching 104*4dc858f2Swiza NUL byte, the 1058625ada8Stshiozak.Fn mbsrtowcs 106cef0afe9Swizplaces the state object pointed to by 1078625ada8Stshiozak.Fa ps 108cef0afe9Swizto an initial state after the conversion has taken place. 1098625ada8Stshiozak.Pp 110cef0afe9SwizThe behaviour of 1118625ada8Stshiozak.Fn mbsrtowcs 112cef0afe9Swizis affected by the 113cef0afe9Swiz.Dv LC_CTYPE 114cef0afe9Swizcategory of the current locale. 1158625ada8Stshiozak.Pp 116cef0afe9SwizThese are the special cases: 11712d1d194Suwe.Bl -tag -width Li 11812d1d194Suwe. 11912d1d194Suwe.It Li "s == NULL || *s == NULL" 120cef0afe9SwizUndefined (may cause the program to crash). 12112d1d194Suwe. 12212d1d194Suwe.It Li "pwcs == NULL" 1233d3c5d42SwizThe conversion has taken place, but the resulting wide-character string 124cef0afe9Swizwas discarded. 125cef0afe9SwizIn this case, the pointer object pointed to by 1268625ada8Stshiozak.Fa s 1278625ada8Stshiozakis not modified and 1288625ada8Stshiozak.Fa n 1298625ada8Stshiozakis ignored. 13012d1d194Suwe. 13112d1d194Suwe.It Li "ps == NULL" 1328625ada8StshiozakThe 1338625ada8Stshiozak.Fn mbsrtowcs 1348625ada8Stshiozakuses its own internal state object to keep the conversion state, 1358625ada8Stshiozakinstead of 1368625ada8Stshiozak.Fa ps 1378625ada8Stshiozakmentioned in this manual page. 1388625ada8Stshiozak.Pp 139cef0afe9SwizCalling any other functions in 1408625ada8Stshiozak.Lb libc 141cef0afe9Swiznever changes the internal state of 1428625ada8Stshiozak.Fn mbsrtowcs , 143cef0afe9Swizwhich is initialized at startup time of the program. 1448625ada8Stshiozak.El 145b3c7e95dSriastradh.Pp 146b3c7e95dSriastradhThe 147b3c7e95dSriastradh.Fn mbsnrtowcs 148b3c7e95dSriastradhfunction behaves identically to 149b3c7e95dSriastradh.Fn mbsrtowcs , 150b3c7e95dSriastradhexcept that the conversion stops after reading at most 151b3c7e95dSriastradh.Fa nmc 152b3c7e95dSriastradhcharacters from the buffer pointed to by 153b3c7e95dSriastradh.Fa s . 1548625ada8Stshiozak.\" ---------------------------------------------------------------------- 1558625ada8Stshiozak.Sh RETURN VALUES 156b3c7e95dSriastradhThe 1578625ada8Stshiozak.Fn mbsrtowcs 158b3c7e95dSriastradhand 159b3c7e95dSriastradh.Fn mbsnrtowcs 160b3c7e95dSriastradhfunctions return: 16112d1d194Suwe.Bl -tag -width Li 16212d1d194Suwe.It Li 0 , No or positive 163cef0afe9SwizThe value returned is the number of elements stored in the array 164cef0afe9Swizpointed to by 1658625ada8Stshiozak.Fa pwcs , 166*4dc858f2Swizexcept for a terminating NUL wide character (if any). 1678625ada8StshiozakIf 1688625ada8Stshiozak.Fa pwcs 169f80b3487Swizis not 170aba3ac5cSwiz.Dv NULL 171f80b3487Swizand the value returned is equal to 1728625ada8Stshiozak.Fa n , 1733d3c5d42Swizthe wide-character string pointed to by 1748625ada8Stshiozak.Fa pwcs 175*4dc858f2Swizis not NUL-terminated. 1768625ada8StshiozakIf 1778625ada8Stshiozak.Fa pwcs 178*4dc858f2Swizis a NULL pointer, the value returned is the number of elements to contain 179*4dc858f2Swizthe whole string converted, except for a terminating NUL wide character. 18012d1d194Suwe.It Li "(size_t)-1" 181cef0afe9SwizThe array indirectly pointed to by 1828625ada8Stshiozak.Fa s 1838625ada8Stshiozakcontains a byte sequence forming invalid character. 184cef0afe9SwizIn this case, 1858625ada8Stshiozak.Fn mbsrtowcs 186cef0afe9Swizsets 187cef0afe9Swiz.Va errno 188cef0afe9Swizto indicate the error. 1898625ada8Stshiozak.El 1908625ada8Stshiozak.\" ---------------------------------------------------------------------- 1918625ada8Stshiozak.Sh ERRORS 192b3c7e95dSriastradhThe 1938625ada8Stshiozak.Fn mbsrtowcs 194b3c7e95dSriastradhand 195b3c7e95dSriastradh.Fn mbsnrtowcs 196b3c7e95dSriastradhfunctions may fail with the following errors: 1978625ada8Stshiozak.Bl -tag -width Er 1988625ada8Stshiozak.It Bq Er EILSEQ 1998625ada8Stshiozak.Fa s 200b3c7e95dSriastradhpoints to a string containing an invalid or incomplete multibyte 201b3c7e95dSriastradhcharacter. 2028625ada8Stshiozak.It Bq Er EINVAL 2038625ada8Stshiozak.Fa ps 204cef0afe9Swizpoints to an invalid or uninitialized mbstate_t object. 2058625ada8Stshiozak.El 2068625ada8Stshiozak.\" ---------------------------------------------------------------------- 2078625ada8Stshiozak.Sh SEE ALSO 2088625ada8Stshiozak.Xr mbrtowc 3 , 2099f64fab4Swiz.Xr mbstowcs 3 , 2109f64fab4Swiz.Xr setlocale 3 2118625ada8Stshiozak.\" ---------------------------------------------------------------------- 2128625ada8Stshiozak.Sh STANDARDS 2138625ada8StshiozakThe 2148625ada8Stshiozak.Fn mbsrtowcs 2158625ada8Stshiozakfunction conforms to 2168625ada8Stshiozak.St -isoC-amd1 . 217b3c7e95dSriastradhThe 218b3c7e95dSriastradh.Li restrict 219b3c7e95dSriastradhqualifier was added by 220dca9ccd3Swiz.St -isoC-99 . 221b3c7e95dSriastradh.Pp 222b3c7e95dSriastradhThe 223b3c7e95dSriastradh.Fn mbsnrtowcs 224b3c7e95dSriastradhfunction conforms to 225b3c7e95dSriastradh.St -p1003.1-2008 . 226