1.\" $NetBSD: mbrtowc.3,v 1.3 2002/03/18 08:02:19 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 MBRTOWC 3 29.Os 30.\" ---------------------------------------------------------------------- 31.Sh NAME 32.Nm mbrtowc 33.Nd converts a multibyte character to a wide character (restartable) 34.\" ---------------------------------------------------------------------- 35.Sh LIBRARY 36.Lb libc 37.\" ---------------------------------------------------------------------- 38.Sh SYNOPSIS 39.Fd #include \*[Lt]wchar.h\*[Gt] 40.Ft size_t 41.Fn mbrtowc "wchar_t * restrict pwc" "const char * restrict s" "size_t n" \ 42"mbstate_t * restrict ps" 43.\" ---------------------------------------------------------------------- 44.Sh DESCRIPTION 45The 46.Fn mbrtowc 47usually converts the multibyte character pointed by 48.Fa s 49to the wide character, and store the wide character 50to the wchar_t object pointed by 51.Fa pwc 52if 53.Fa pwc 54is non-null and 55.Fa s 56points a valid character. 57The conversion is taken place 58with conforming to and changing the conversion state 59described in the mbstate_t object pointed by 60.Fa ps . 61This function may examine at most 62.Fa n 63bytes of the array beginning from 64.Fa s . 65.Pp 66If 67.Fa s 68points a valid character and the character corresponds to a null wide 69character, then the 70.Fn mbrtowc 71places the mbstate_t object pointed by 72.Fa ps 73to an initial conversion state. 74.Pp 75Unlike 76.Xr mbtowc 3 , 77the 78.Fn mbrtowc 79may accept the byte sequence pointed by 80.Fa s 81not forming complete multibyte character 82but being possible for a part of a valid character. 83In this case, this function will accept the all of such bytes 84and save them into the conversion state object pointed by 85.Fa ps . 86They will be used at the subsequent call of this function to restart 87the conversion suspended. 88.Pp 89The behaviour of the 90.Fn mbrtowc 91is affected by LC_CTYPE category of the current locale. 92.Pp 93There are the special cases: 94.Bl -tag -width 012345678901 95.It "s == NULL" 96The 97.Fn mbrtowc 98sets the conversion state object pointed by 99.Fa ps 100to an initial state and always return 0. 101Unlike 102.Xr mbtowc 3 , 103the value returned does not indicate whether the current encoding of 104the locale is state-dependent. 105.Pp 106In this case, 107The 108.Fn mbrtowc 109ignores 110.Fa pwc 111and 112.Fa n , 113and is equivalent to the following call: 114.Pp 115.Bd -literal 116mbrtowc(NULL, "", 1, ps); 117.Ed 118.It "pwc == NULL" 119The conversion from a multibyte character to a wide character is 120taken place and the conversion state may be affected, but the result 121wide character is discarded. 122.It "ps == NULL" 123The 124.Fn mbrtowc 125uses its own internal state object to keep the conversion state, 126instead of 127.Fa ps 128mentioned in this manual page. 129.Pp 130Calling any other functions in the 131.Lb libc 132never change the internal 133state of the 134.Fn mbrtowc , 135that is initialized at startup time of the program. 136.El 137.\" ---------------------------------------------------------------------- 138.Sh RETURN VALUES 139In the usual cases, the 140.Fn mbrtowc 141returns: 142.Bl -tag -width 012345678901 143.It 0 144The next bytes pointed by 145.Fa s 146forms a null character. 147.It positive 148If 149.Fa s 150is points an valid character, 151the 152.Fn mbrtowc 153returns the number of bytes consisting the character. 154.It (size_t)-2 155.Fa s 156points the byte sequence which is possible to consist a part of valid 157multibyte character but incomplete. 158When 159.Fa n 160is at least MB_CUR_MAX, 161this case can only occur if the array pointed 162.Fa s 163contains redundant shift sequence. 164.It (size_t)-1 165.Fa s 166points a illegal byte sequence which does not form a valid multibyte 167character. 168In this case, the 169.Fn mbrtowc 170sets errno to indicate the error. 171.El 172.\" ---------------------------------------------------------------------- 173.Sh ERRORS 174The 175.Fn mbrtowc 176may causes an error in the following case: 177.Bl -tag -width Er 178.It Bq Er EILSEQ 179.Fa s 180points an invalid or incomplete multibyte character. 181.It Bq Er EINVAL 182.Fa ps 183points an invalid or uninitialized mbstate_t object. 184.El 185.\" ---------------------------------------------------------------------- 186.Sh SEE ALSO 187.Xr mbrlen 3 , 188.Xr mbtowc 3 , 189.Xr setlocale 3 190.\" ---------------------------------------------------------------------- 191.Sh STANDARDS 192The 193.Fn mbrtowc 194function conforms to 195.St -isoC-amd1 . 196The restrict qualifier is added at 197.St -isoC99 . 198