1 .\" $NetBSD: mbrlen.3,v 1.9 2008/02/28 19:36:51 tnozaki 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 get number of bytes in a multibyte character (restartable)
34 .\" ----------------------------------------------------------------------
37 .\" ----------------------------------------------------------------------
41 .Fn mbrlen "const char * restrict s" "size_t n" "mbstate_t * restrict ps"
42 .\" ----------------------------------------------------------------------
46 function usually determines the number of bytes in
47 a multibyte character pointed to by
50 This function shall only examine max n bytes of the array beginning from
54 is equivalent to the following call (except
56 is evaluated only once):
57 .Bd -literal -offset indent
58 mbrtowc(NULL, s, n, (ps != NULL) ? ps : \*[Am]internal);
63 is an internal state object.
65 In state-dependent encodings,
67 may point to the special sequence bytes to change the shift-state.
68 Although such sequence bytes corresponds to no individual
69 wide-character code, these affect the conversion state object pointed
74 treats the special sequence bytes
75 as if these are a part of the subsequent multibyte character.
80 may accept the byte sequence when it is not a complete character
81 but possibly contains part of a valid character.
82 In this case, this function will accept all such bytes
83 and save them into the conversion state object pointed to by
85 They will be used on subsequent calls of this function to restart
86 the conversion suspended.
92 category of the current locale.
94 These are the special cases:
95 .Bl -tag -width 0123456789
98 sets the conversion state object pointed to by
100 to an initial state and always returns 0.
103 the value returned does not indicate whether the current encoding of
104 the locale is state-dependent.
114 bytes of the array pointed to by
116 never form a complete character.
119 always returns (size_t)-2.
122 uses its own internal state object to keep the conversion state,
125 mentioned in this manual page.
127 Calling any other functions in
129 never changes the internal
136 category of the current locale.
139 calls cause the internal state of this function to be indeterminate.
140 This internal state is initialized at startup time of the program.
142 .\" ----------------------------------------------------------------------
147 .Bl -tag -width 0123456789
153 The value returned is
154 a number of bytes for the valid multibyte character pointed to by
156 There are no cases that this value is greater than
163 points to the byte sequence which possibly contains part of a valid
164 multibyte character, but which is incomplete.
169 this case can only occur if the array pointed to by
171 contains a redundant shift sequence.
174 points to an illegal byte sequence which does not form a valid multibyte
180 to indicate the error.
182 .\" ----------------------------------------------------------------------
185 may cause an error in the following case:
189 points to an invalid multibyte character.
192 points to an invalid or uninitialized mbstate_t object.
194 .\" ----------------------------------------------------------------------
199 .\" ----------------------------------------------------------------------
205 The restrict qualifier is added at