1*01869ca4Swiz.\" $NetBSD: mbrlen.3,v 1.10 2017/07/03 21:32:49 wiz Exp $ 28625ada8Stshiozak.\" 38625ada8Stshiozak.\" Copyright (c)2002 Citrus Project, 48625ada8Stshiozak.\" All rights reserved. 58625ada8Stshiozak.\" 68625ada8Stshiozak.\" Redistribution and use in source and binary forms, with or without 78625ada8Stshiozak.\" modification, are permitted provided that the following conditions 88625ada8Stshiozak.\" are met: 98625ada8Stshiozak.\" 1. Redistributions of source code must retain the above copyright 108625ada8Stshiozak.\" notice, this list of conditions and the following disclaimer. 118625ada8Stshiozak.\" 2. Redistributions in binary form must reproduce the above copyright 128625ada8Stshiozak.\" notice, this list of conditions and the following disclaimer in the 138625ada8Stshiozak.\" documentation and/or other materials provided with the distribution. 148625ada8Stshiozak.\" 158625ada8Stshiozak.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 168625ada8Stshiozak.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 178625ada8Stshiozak.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 188625ada8Stshiozak.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 198625ada8Stshiozak.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 208625ada8Stshiozak.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 218625ada8Stshiozak.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 228625ada8Stshiozak.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 238625ada8Stshiozak.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 248625ada8Stshiozak.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 258625ada8Stshiozak.\" SUCH DAMAGE. 268625ada8Stshiozak.\" 279f64fab4Swiz.Dd February 3, 2002 288625ada8Stshiozak.Dt MBRLEN 3 298625ada8Stshiozak.Os 308625ada8Stshiozak.\" ---------------------------------------------------------------------- 318625ada8Stshiozak.Sh NAME 328625ada8Stshiozak.Nm mbrlen 33cef0afe9Swiz.Nd get number of bytes in a multibyte character (restartable) 348625ada8Stshiozak.\" ---------------------------------------------------------------------- 358625ada8Stshiozak.Sh LIBRARY 368625ada8Stshiozak.Lb libc 378625ada8Stshiozak.\" ---------------------------------------------------------------------- 388625ada8Stshiozak.Sh SYNOPSIS 39472351e1Swiz.In wchar.h 4047d7f820Stnozaki.Ft size_t 418625ada8Stshiozak.Fn mbrlen "const char * restrict s" "size_t n" "mbstate_t * restrict ps" 428625ada8Stshiozak.\" ---------------------------------------------------------------------- 438625ada8Stshiozak.Sh DESCRIPTION 448625ada8StshiozakThe 458625ada8Stshiozak.Fn mbrlen 46cef0afe9Swizfunction usually determines the number of bytes in 47cef0afe9Swiza multibyte character pointed to by 488625ada8Stshiozak.Fa s 49cef0afe9Swizand returns it. 508625ada8StshiozakThis function shall only examine max n bytes of the array beginning from 518625ada8Stshiozak.Fa s . 528625ada8Stshiozak.Pp 538625ada8Stshiozak.Fn mbrlen 548625ada8Stshiozakis equivalent to the following call (except 558625ada8Stshiozak.Fa ps 568625ada8Stshiozakis evaluated only once): 57cef0afe9Swiz.Bd -literal -offset indent 58*01869ca4Swizmbrtowc(NULL, s, n, (ps != NULL) ? ps : &internal); 598625ada8Stshiozak.Ed 608625ada8Stshiozak.Pp 618625ada8StshiozakHere, 628625ada8Stshiozak.Fa internal 638625ada8Stshiozakis an internal state object. 648625ada8Stshiozak.Pp 658625ada8StshiozakIn state-dependent encodings, 668625ada8Stshiozak.Fa s 67cef0afe9Swizmay point to the special sequence bytes to change the shift-state. 688625ada8StshiozakAlthough such sequence bytes corresponds to no individual 69cef0afe9Swizwide-character code, these affect the conversion state object pointed 70cef0afe9Swizto by 718625ada8Stshiozak.Fa ps , 728625ada8Stshiozakand the 738625ada8Stshiozak.Fn mbrlen 748625ada8Stshiozaktreats the special sequence bytes 758625ada8Stshiozakas if these are a part of the subsequent multibyte character. 768625ada8Stshiozak.Pp 778625ada8StshiozakUnlike 788625ada8Stshiozak.Xr mblen 3 , 798625ada8Stshiozak.Fn mbrlen 80cef0afe9Swizmay accept the byte sequence when it is not a complete character 81cef0afe9Swizbut possibly contains part of a valid character. 82cef0afe9SwizIn this case, this function will accept all such bytes 83cef0afe9Swizand save them into the conversion state object pointed to by 848625ada8Stshiozak.Fa ps . 85cef0afe9SwizThey will be used on subsequent calls of this function to restart 868625ada8Stshiozakthe conversion suspended. 878625ada8Stshiozak.Pp 88cef0afe9SwizThe behaviour of 898625ada8Stshiozak.Fn mbrlen 90cef0afe9Swizis affected by the 91cef0afe9Swiz.Dv LC_CTYPE 92cef0afe9Swizcategory of the current locale. 938625ada8Stshiozak.Pp 94cef0afe9SwizThese are the special cases: 958625ada8Stshiozak.Bl -tag -width 0123456789 968625ada8Stshiozak.It "s == NULL" 978625ada8Stshiozak.Fn mbrlen 98cef0afe9Swizsets the conversion state object pointed to by 998625ada8Stshiozak.Fa ps 100cef0afe9Swizto an initial state and always returns 0. 1018625ada8StshiozakUnlike 1028625ada8Stshiozak.Xr mblen 3 , 1038625ada8Stshiozakthe value returned does not indicate whether the current encoding of 1048625ada8Stshiozakthe locale is state-dependent. 1058625ada8Stshiozak.Pp 106cef0afe9SwizIn this case, 1078625ada8Stshiozak.Fn mbrlen 1088625ada8Stshiozakignores 1098625ada8Stshiozak.Fa n . 1108625ada8Stshiozak.It "n == 0" 1118625ada8StshiozakIn this case, 1128625ada8Stshiozakthe first 1138625ada8Stshiozak.Fa n 114cef0afe9Swizbytes of the array pointed to by 1158625ada8Stshiozak.Fa s 1163225ede1Swiznever form a complete character. 117cef0afe9SwizThus, 1188625ada8Stshiozak.Fn mbrlen 1198625ada8Stshiozakalways returns (size_t)-2. 1208625ada8Stshiozak.It "ps == NULL" 1218625ada8Stshiozak.Fn mbrlen 1228625ada8Stshiozakuses its own internal state object to keep the conversion state, 1238625ada8Stshiozakinstead of 1248625ada8Stshiozak.Fa ps 1258625ada8Stshiozakmentioned in this manual page. 1268625ada8Stshiozak.Pp 127cef0afe9SwizCalling any other functions in 1288625ada8Stshiozak.Lb libc 129cef0afe9Swiznever changes the internal 130cef0afe9Swizstate of 1318625ada8Stshiozak.Fn mbrlen , 1328625ada8Stshiozakexcept for calling 1338625ada8Stshiozak.Xr setlocale 3 134cef0afe9Swizwith a changing 135cef0afe9Swiz.Dv LC_CTYPE 136cef0afe9Swizcategory of the current locale. 1378625ada8StshiozakSuch 1388625ada8Stshiozak.Xr setlocale 3 139cef0afe9Swizcalls cause the internal state of this function to be indeterminate. 1408625ada8StshiozakThis internal state is initialized at startup time of the program. 1418625ada8Stshiozak.El 1428625ada8Stshiozak.\" ---------------------------------------------------------------------- 1438625ada8Stshiozak.Sh RETURN VALUES 1448625ada8StshiozakThe 1458625ada8Stshiozak.Fn mbrlen 1468625ada8Stshiozakreturns: 1478625ada8Stshiozak.Bl -tag -width 0123456789 1488625ada8Stshiozak.It "0" 1498625ada8Stshiozak.Fa s 150f80b3487Swizpoints to a nul byte 151cef0afe9Swiz.Pq Sq \e0 . 1528625ada8Stshiozak.It "positive" 1538625ada8StshiozakThe value returned is 154cef0afe9Swiza number of bytes for the valid multibyte character pointed to by 1558625ada8Stshiozak.Fa s . 156cef0afe9SwizThere are no cases that this value is greater than 1578625ada8Stshiozak.Fa n 158cef0afe9Swizor the value of the 159cef0afe9Swiz.Dv MB_CUR_MAX 160cef0afe9Swizmacro. 1618625ada8Stshiozak.It "(size_t)-2" 1628625ada8Stshiozak.Fa s 163cef0afe9Swizpoints to the byte sequence which possibly contains part of a valid 164cef0afe9Swizmultibyte character, but which is incomplete. 1658625ada8StshiozakWhen 1668625ada8Stshiozak.Fa n 167cef0afe9Swizis at least 168cef0afe9Swiz.Dv MB_CUR_MAX , 169cef0afe9Swizthis case can only occur if the array pointed to by 1708625ada8Stshiozak.Fa s 171cef0afe9Swizcontains a redundant shift sequence. 1728625ada8Stshiozak.It "(size_t)-1" 1738625ada8Stshiozak.Fa s 174cef0afe9Swizpoints to an illegal byte sequence which does not form a valid multibyte 1758625ada8Stshiozakcharacter. 176cef0afe9SwizIn this case, 1778625ada8Stshiozak.Fn mbrtowc 178cef0afe9Swizsets 179cef0afe9Swiz.Va errno 180cef0afe9Swizto indicate the error. 1818625ada8Stshiozak.El 1828625ada8Stshiozak.\" ---------------------------------------------------------------------- 1838625ada8Stshiozak.Sh ERRORS 1848625ada8Stshiozak.Fn mbrlen 185cef0afe9Swizmay cause an error in the following case: 1868625ada8Stshiozak.Bl -tag -width Er 1878625ada8Stshiozak.It Bq Er EILSEQ 1888625ada8Stshiozak.Fa s 189cef0afe9Swizpoints to an invalid multibyte character. 1908625ada8Stshiozak.It Bq Er EINVAL 1918625ada8Stshiozak.Fa ps 192cef0afe9Swizpoints to an invalid or uninitialized mbstate_t object. 1938625ada8Stshiozak.El 1948625ada8Stshiozak.\" ---------------------------------------------------------------------- 1958625ada8Stshiozak.Sh SEE ALSO 1968625ada8Stshiozak.Xr mblen 3 , 1979f64fab4Swiz.Xr mbrtowc 3 , 1989f64fab4Swiz.Xr setlocale 3 1998625ada8Stshiozak.\" ---------------------------------------------------------------------- 2008625ada8Stshiozak.Sh STANDARDS 2018625ada8StshiozakThe 2028625ada8Stshiozak.Fn mbrlen 2038625ada8Stshiozakfunction conforms to 2048625ada8Stshiozak.St -isoC-amd1 . 2058625ada8StshiozakThe restrict qualifier is added at 206dca9ccd3Swiz.St -isoC-99 . 207