mbrlen.3 (279062fae149e105dae7c28b638d49ba5715725d) | mbrlen.3 (8b8109275c1a583e96171df08e3136151c02279e) |
---|---|
1.\" Copyright (c) 2002 Tim J. Robbins | 1.\" Copyright (c) 2002-2004 Tim J. Robbins |
2.\" All rights reserved. 3.\" 4.\" Redistribution and use in source and binary forms, with or without 5.\" modification, are permitted provided that the following conditions 6.\" are met: 7.\" 1. Redistributions of source code must retain the above copyright 8.\" notice, this list of conditions and the following disclaimer. 9.\" 2. Redistributions in binary form must reproduce the above copyright --- 9 unchanged lines hidden (view full) --- 19.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 20.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 21.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 22.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 23.\" SUCH DAMAGE. 24.\" 25.\" $FreeBSD$ 26.\" | 2.\" All rights reserved. 3.\" 4.\" Redistribution and use in source and binary forms, with or without 5.\" modification, are permitted provided that the following conditions 6.\" are met: 7.\" 1. Redistributions of source code must retain the above copyright 8.\" notice, this list of conditions and the following disclaimer. 9.\" 2. Redistributions in binary form must reproduce the above copyright --- 9 unchanged lines hidden (view full) --- 19.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 20.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 21.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 22.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 23.\" SUCH DAMAGE. 24.\" 25.\" $FreeBSD$ 26.\" |
27.Dd November 11, 2002 | 27.Dd April 7, 2004 |
28.Dt MBRLEN 3 29.Os 30.Sh NAME 31.Nm mbrlen 32.Nd "get number of bytes in a character (restartable)" 33.Sh LIBRARY 34.Lb libc 35.Sh SYNOPSIS 36.In wchar.h 37.Ft size_t 38.Fn mbrlen "const char * restrict s" "size_t n" "mbstate_t * restrict ps" 39.Sh DESCRIPTION 40The 41.Fn mbrlen | 28.Dt MBRLEN 3 29.Os 30.Sh NAME 31.Nm mbrlen 32.Nd "get number of bytes in a character (restartable)" 33.Sh LIBRARY 34.Lb libc 35.Sh SYNOPSIS 36.In wchar.h 37.Ft size_t 38.Fn mbrlen "const char * restrict s" "size_t n" "mbstate_t * restrict ps" 39.Sh DESCRIPTION 40The 41.Fn mbrlen |
42function determines the number of bytes constituting the 43multibyte character sequence pointed to by 44.Fa s , 45examining at most | 42function inspects at most |
46.Fa n | 43.Fa n |
47bytes. | 44bytes pointed to by 45.Fa s 46to determine the number of bytes needed to complete the next 47multibyte character. |
48.Pp 49The 50.Vt mbstate_t 51argument, 52.Fa ps , 53is used to keep track of the shift state. 54If it is 55.Dv NULL , 56.Fn mbrlen 57uses an internal, static 58.Vt mbstate_t | 48.Pp 49The 50.Vt mbstate_t 51argument, 52.Fa ps , 53is used to keep track of the shift state. 54If it is 55.Dv NULL , 56.Fn mbrlen 57uses an internal, static 58.Vt mbstate_t |
59object. | 59object, which is initialized to the initial conversion state 60at program startup. |
60.Pp 61It is equivalent to: 62.Pp 63.Dl "mbrtowc(NULL, s, n, ps);" 64.Pp 65Except that when 66.Fa ps 67is a --- 4 unchanged lines hidden (view full) --- 72.Vt mbstate_t 73object to keep track of the shift state. 74.Sh RETURN VALUES 75The 76.Fn mbrlen 77functions returns: 78.Bl -tag -width indent 79.It 0 | 61.Pp 62It is equivalent to: 63.Pp 64.Dl "mbrtowc(NULL, s, n, ps);" 65.Pp 66Except that when 67.Fa ps 68is a --- 4 unchanged lines hidden (view full) --- 73.Vt mbstate_t 74object to keep track of the shift state. 75.Sh RETURN VALUES 76The 77.Fn mbrlen 78functions returns: 79.Bl -tag -width indent 80.It 0 |
80The first | 81The next |
81.Fa n | 82.Fa n |
82or fewer bytes of 83.Fa s | 83or fewer bytes |
84represent the null wide character 85.Pq Li "L'\e0'" . 86.It >0 | 84represent the null wide character 85.Pq Li "L'\e0'" . 86.It >0 |
87The first | 87The next |
88.Fa n | 88.Fa n |
89or fewer bytes of 90.Fa s | 89or fewer bytes |
91represent a valid character, | 90represent a valid character, |
92.Fn mbrtowc 93returns the length (in bytes) of the multibyte sequence. | 91.Fn mbrlen 92returns the number of bytes used to complete the multibyte character. |
94.It Po Vt size_t Pc Ns \-2 | 93.It Po Vt size_t Pc Ns \-2 |
95The first | 94The next |
96.Fa n | 95.Fa n |
97bytes of 98.Fa s 99are an incomplete multibyte sequence. | 96contribute to, but do not complete, a valid multibyte character sequence, 97and all 98.Fa n 99bytes have been processed. |
100.It Po Vt size_t Pc Ns \-1 | 100.It Po Vt size_t Pc Ns \-1 |
101The byte sequence pointed to by 102.Fa s 103is an invalid multibyte sequence. | 101An encoding error has occurred. 102The next 103.Fa fn 104or fewer bytes do not contribute to a valid multibyte character. |
104.El 105.Sh EXAMPLES | 105.El 106.Sh EXAMPLES |
106A function which calculates the number of characters in a multibyte | 107A function that calculates the number of characters in a multibyte |
107character string: 108.Bd -literal -offset indent 109size_t 110nchars(const char *s) 111{ 112 size_t charlen, chars; 113 mbstate_t mbs; 114 --- 8 unchanged lines hidden (view full) --- 123 return (chars); 124} 125.Ed 126.Sh ERRORS 127The 128.Fn mbrlen 129function will fail if: 130.Bl -tag -width Er | 108character string: 109.Bd -literal -offset indent 110size_t 111nchars(const char *s) 112{ 113 size_t charlen, chars; 114 mbstate_t mbs; 115 --- 8 unchanged lines hidden (view full) --- 124 return (chars); 125} 126.Ed 127.Sh ERRORS 128The 129.Fn mbrlen 130function will fail if: 131.Bl -tag -width Er |
131.\".It Bq Er EINVAL 132.\"Invalid argument. | |
133.It Bq Er EILSEQ 134An invalid multibyte sequence was detected. | 132.It Bq Er EILSEQ 133An invalid multibyte sequence was detected. |
134.It Bq Er EINVAL 135The conversion state is invalid. |
|
135.El 136.Sh SEE ALSO 137.Xr mblen 3 , | 136.El 137.Sh SEE ALSO 138.Xr mblen 3 , |
138.Xr mbrtowc 3 | 139.Xr mbrtowc 3 , 140.Xr multibyte 3 |
139.Sh STANDARDS 140The 141.Fn mbrlen 142function conforms to 143.St -isoC-99 . | 141.Sh STANDARDS 142The 143.Fn mbrlen 144function conforms to 145.St -isoC-99 . |
144.Sh BUGS 145The current implementation does not support shift states. | |