1.\" $NetBSD: mbsrtowcs.3,v 1.4 2002/10/01 17:02:57 wiz Exp $ 2.\" 3.\" Copyright (c)2002 Citrus Project, 4.\" All rights reserved. 5.\" 6.\" Redistribution and use in source and binary forms, with or without 7.\" modification, are permitted provided that the following conditions 8.\" are met: 9.\" 1. Redistributions of source code must retain the above copyright 10.\" notice, this list of conditions and the following disclaimer. 11.\" 2. Redistributions in binary form must reproduce the above copyright 12.\" notice, this list of conditions and the following disclaimer in the 13.\" documentation and/or other materials provided with the distribution. 14.\" 15.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25.\" SUCH DAMAGE. 26.\" 27.Dd February 4, 2002 28.Dt MBSRTOWCS 3 29.Os 30.\" ---------------------------------------------------------------------- 31.Sh NAME 32.Nm mbsrtowcs 33.Nd converts a multibyte character string to a wide character string \ 34(restartable) 35.\" ---------------------------------------------------------------------- 36.Sh LIBRARY 37.Lb libc 38.\" ---------------------------------------------------------------------- 39.Sh SYNOPSIS 40.Fd #include \*[Lt]wchar.h\*[Gt] 41.Ft size_t 42.Fn mbsrtowcs "wchar_t * restrict pwcs" "const char ** restrict s" "size_t n" \ 43"mbstate_t * restrict ps" 44.\" ---------------------------------------------------------------------- 45.Sh DESCRIPTION 46The 47.Fn mbsrtowcs 48converts the multibyte character string indirectly pointed by 49.Fa s 50to the corresponding wide character string, and stores it to the 51array pointed by 52.Fa pwcs . 53The conversion stops due to the following reasons: 54.Bl -bullet 55.It 56The conversion reaches a null byte. 57In this case, the null byte is also converted. 58.It 59The 60.Fn mbsrtowcs 61has already stored 62.Fa n 63wide characters. 64.It 65The conversion encounters an invalid character. 66.El 67.Pp 68Each characters will be converted as if 69.Xr mbrtowc 3 70is continuously called. 71.Pp 72After conversion, 73if 74.Fa pwcs 75is not NULL pointer, 76the pointer object pointed by 77.Fa s 78is NULL pointer (if the conversion is stopped due to reach a null byte) 79or the first byte of the character just after the last character converted. 80.Pp 81If 82.Fa pwcs 83is not null pointer and the conversion is stopped due to reach 84a null byte, the 85.Fn mbsrtowcs 86places the state object pointed by 87.Fa ps 88to an initial state after the conversion is taken place. 89.Pp 90The behaviour of the 91.Fn mbsrtowcs 92is affected by LC_CTYPE category of the current locale. 93.Pp 94There are special cases: 95.Bl -tag -width 012345678901 96.It "s == NULL || *s == NULL" 97undefined (may causes the program to crash). 98.It "pwcs == NULL" 99The conversion is taken place, but the result wide character string 100is discarded. 101In this case, the pointer object pointed by 102.Fa s 103is not modified and 104.Fa n 105is ignored. 106.It "ps == NULL" 107The 108.Fn mbsrtowcs 109uses its own internal state object to keep the conversion state, 110instead of 111.Fa ps 112mentioned in this manual page. 113.Pp 114Calling any other functions in the 115.Lb libc 116never change the internal 117state of the 118.Fn mbsrtowcs , 119that is initialized at startup time of the program. 120.El 121.\" ---------------------------------------------------------------------- 122.Sh RETURN VALUES 123The 124.Fn mbsrtowcs 125returns 126.Bl -tag -width 012345678901 127.It 0 or positive 128The value returned is the number of elements stored to the array pointed by 129.Fa pwcs , 130except for a terminate null wide character (if any). 131If 132.Fa pwcs 133is not null and the value returned is equal to 134.Fa n , 135the wide character string pointed by 136.Fa pwcs 137is not null terminated. 138If 139.Fa pwcs 140is a null pointer, the value returned is the number of elements to contain 141the whole string converted, except for a terminate null wide character. 142.It (size_t)-1 143The array indirectly pointed by 144.Fa s 145contains a byte sequence forming invalid character. 146In this case, the 147.Fn mbsrtowcs 148sets errno to indicate the error. 149.El 150.\" ---------------------------------------------------------------------- 151.Sh ERRORS 152The 153.Fn mbsrtowcs 154may causes an error in the following case: 155.Bl -tag -width Er 156.It Bq Er EILSEQ 157The pointer pointed by 158.Fa s 159points an invalid or incomplete multibyte character. 160.It Bq Er EINVAL 161.Fa ps 162points an invalid or uninitialized mbstate_t object. 163.El 164.\" ---------------------------------------------------------------------- 165.Sh SEE ALSO 166.Xr mbrtowc 3 , 167.Xr mbstowcs 3 , 168.Xr setlocale 3 169.\" ---------------------------------------------------------------------- 170.Sh STANDARDS 171The 172.Fn mbsrtowcs 173function conforms to 174.St -isoC-amd1 . 175The restrict qualifier is added at 176.St -isoC99 . 177