1 .\" $NetBSD: mbrtowc.3,v 1.7 2006/10/14 07:51:01 wiz Exp $
3 .\" Copyright (c)2002 Citrus Project,
4 .\" All rights reserved.
6 .\" Redistribution and use in source and binary forms, with or without
7 .\" modification, are permitted provided that the following conditions
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.
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
30 .\" ----------------------------------------------------------------------
33 .Nd converts a multibyte character to a wide character (restartable)
34 .\" ----------------------------------------------------------------------
37 .\" ----------------------------------------------------------------------
41 .Fn mbrtowc "wchar_t * restrict pwc" "const char * restrict s" "size_t n" \
42 "mbstate_t * restrict ps"
43 .\" ----------------------------------------------------------------------
47 usually converts the multibyte character pointed to by
49 to a wide character, and stores the wide character
50 to the wchar_t object pointed to by
58 points to a valid character.
59 The conversion happens in accordance with, and changes the conversion
60 state described in the mbstate_t object pointed to by
62 This function may examine at most
64 bytes of the array beginning from
69 points to a valid character and the character corresponds to a nul wide
72 places the mbstate_t object pointed to by
74 to an initial conversion state.
80 may accept the byte sequence pointed to by
82 not forming a complete multibyte character
83 but which may be part of a valid character.
84 In this case, this function will accept all such bytes
85 and save them into the conversion state object pointed to by
87 They will be used at subsequent calls of this function to restart
88 the conversion suspended.
94 category of the current locale.
96 These are the special cases:
97 .Bl -tag -width 012345678901
100 sets the conversion state object pointed to by
102 to an initial state and always returns 0.
105 the value returned does not indicate whether the current encoding of
106 the locale is state-dependent.
114 and is equivalent to the following call:
115 .Bd -literal -offset indent
116 mbrtowc(NULL, "", 1, ps);
119 The conversion from a multibyte character to a wide character has
120 taken place and the conversion state may be affected, but the resulting
121 wide character is discarded.
124 uses its own internal state object to keep the conversion state,
127 mentioned in this manual page.
129 Calling any other functions in
131 never changes the internal state of
133 which is initialized at startup time of the program.
135 .\" ----------------------------------------------------------------------
140 .Bl -tag -width 012345678901
142 The next bytes pointed to by
144 form a nul character.
148 points to a valid character,
150 returns the number of bytes in the character.
153 points to a byte sequence which possibly contains part of a valid
154 multibyte character, but which is incomplete.
159 this case can only occur if the array pointed to by
161 contains a redundant shift sequence.
164 points to an illegal byte sequence which does not form a valid multibyte
170 to indicate the error.
172 .\" ----------------------------------------------------------------------
175 may cause an error in the following case:
179 points to an invalid or incomplete multibyte character.
182 points to an invalid or uninitialized mbstate_t object.
184 .\" ----------------------------------------------------------------------
189 .\" ----------------------------------------------------------------------
195 The restrict qualifier is added at