1.\" $OpenBSD: mbrlen.3,v 1.4 2013/06/05 03:39:22 tedu Exp $ 2.\" $NetBSD: mbrlen.3,v 1.5 2003/09/08 17:54:31 wiz Exp $ 3.\" 4.\" Copyright (c)2002 Citrus Project, 5.\" All rights reserved. 6.\" 7.\" Redistribution and use in source and binary forms, with or without 8.\" modification, are permitted provided that the following conditions 9.\" are met: 10.\" 1. Redistributions of source code must retain the above copyright 11.\" notice, this list of conditions and the following disclaimer. 12.\" 2. Redistributions in binary form must reproduce the above copyright 13.\" notice, this list of conditions and the following disclaimer in the 14.\" documentation and/or other materials provided with the distribution. 15.\" 16.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 17.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 20.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26.\" SUCH DAMAGE. 27.\" 28.Dd $Mdocdate: June 5 2013 $ 29.Dt MBRLEN 3 30.Os 31.\" ---------------------------------------------------------------------- 32.Sh NAME 33.Nm mbrlen 34.Nd get number of bytes in a multibyte character (restartable) 35.\" ---------------------------------------------------------------------- 36.Sh SYNOPSIS 37.In wchar.h 38.Ft size_t 39.Fn mbrlen "const char * restrict s" "size_t n" "mbstate_t * restrict ps" 40.\" ---------------------------------------------------------------------- 41.Sh DESCRIPTION 42The 43.Fn mbrlen 44function usually determines the number of bytes in 45a multibyte character pointed to by 46.Fa s 47and returns it. 48This function shall only examine max n bytes of the array beginning from 49.Fa s . 50.Pp 51.Fn mbrlen 52is equivalent to the following call (except 53.Fa ps 54is evaluated only once): 55.Bd -literal -offset indent 56mbrtowc(NULL, s, n, (ps != NULL) ? ps : &internal); 57.Ed 58.Pp 59Here, 60.Fa internal 61is an internal state object. 62.Pp 63In state-dependent encodings, 64.Fa s 65may point to the special sequence bytes to change the shift-state. 66Although such sequence bytes corresponds to no individual 67wide-character code, these affect the conversion state object pointed to by 68.Fa ps , 69and the 70.Fn mbrlen 71treats the special sequence bytes 72as if these are a part of the subsequent multibyte character. 73.Pp 74Unlike 75.Xr mblen 3 , 76.Fn mbrlen 77may accept the byte sequence when it is not a complete character 78but possibly contains part of a valid character. 79In this case, this function will accept all such bytes 80and save them into the conversion state object pointed to by 81.Fa ps . 82They will be used on subsequent calls of this function to restart 83the conversion suspended. 84.Pp 85The behaviour of the 86.Fn mbrlen 87is affected by 88.Dv LC_CTYPE 89category of the current locale. 90.Pp 91There are the special cases: 92.Bl -tag -width 0123456789 93.It "s == NULL" 94.Fn mbrlen 95sets the conversion state object pointed to by 96.Fa ps 97to an initial state and always returns 0. 98Unlike 99.Xr mblen 3 , 100the value returned does not indicate whether the current encoding of 101the locale is state-dependent. 102.Pp 103In this case, 104.Fn mbrlen 105ignores 106.Fa n . 107.It "n == 0" 108In this case, 109the first 110.Fa n 111bytes of the array pointed to by 112.Fa s 113never form a complete character. 114Thus, 115.Fn mbrlen 116always returns (size_t)-2. 117.It "ps == NULL" 118.Fn mbrlen 119uses its own internal state object to keep the conversion state, 120instead of 121.Fa ps 122mentioned in this manual page. 123.Pp 124Calling any other functions in 125.Em libc 126never change the internal 127state of 128.Fn mbrlen , 129except for calling 130.Xr setlocale 3 131with a changing 132.Dv LC_CTYPE 133category of the current locale. 134Such 135.Xr setlocale 3 136calls cause the internal state of this function to be indeterminate. 137This internal state is initialized at startup time of the program. 138.El 139.\" ---------------------------------------------------------------------- 140.Sh RETURN VALUES 141The 142.Fn mbrlen 143returns: 144.Bl -tag -width 0123456789 145.It "0" 146.Fa s 147points to a null byte 148.Pq Sq \e0 . 149.It "positive" 150The value returned is 151a number of bytes for the valid multibyte character pointed to by 152.Fa s . 153There are no cases where this value is greater than 154.Fa n 155or the value of the 156.Dv MB_CUR_MAX 157macro. 158.It "(size_t)-2" 159.Fa s 160points to the byte sequence which possibly contains part of a valid 161multibyte character, but which is incomplete. 162When 163.Fa n 164is at least 165.Dv MB_CUR_MAX 166can only occur if the array pointed to by 167.Fa s 168contains a redundant shift sequence. 169.It "(size_t)-1" 170.Fa s 171points to an illegal byte sequence which does not form a valid multibyte 172character. 173In this case, 174.Fn mbrtowc 175sets 176.Va errno 177to indicate the error. 178.El 179.\" ---------------------------------------------------------------------- 180.Sh ERRORS 181.Fn mbrlen 182may cause an error in the following cases: 183.Bl -tag -width Er 184.It Bq Er EILSEQ 185.Fa s 186points to an invalid multibyte character. 187.It Bq Er EINVAL 188.Fa ps 189points to an invalid or uninitialized mbstate_t object. 190.El 191.\" ---------------------------------------------------------------------- 192.Sh SEE ALSO 193.Xr mblen 3 , 194.Xr mbrtowc 3 , 195.Xr setlocale 3 196.\" ---------------------------------------------------------------------- 197.Sh STANDARDS 198The 199.Fn mbrlen 200function conforms to 201.\" .St -isoC-amd1 . 202ISO/IEC 9899/AMD1:1995 203.Pq Dq ISO C90, Amendment 1 . 204The restrict qualifier is added at 205.\" .St -isoC99 . 206ISO/IEC 9899/1999 207.Pq Dq ISO C99 . 208