xref: /freebsd/lib/libc/locale/mbrlen.3 (revision e92a3d83fcba95f35d5f162df92f2d5b8351c2e3)
1.\" Copyright (c) 2002 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
10.\"    notice, this list of conditions and the following disclaimer in the
11.\"    documentation and/or other materials provided with the distribution.
12.\"
13.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
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.Dd August 16, 2002
27.Dt MBRLEN 3
28.Os
29.Sh NAME
30.Nm mbrlen
31.Nd "get number of bytes in a character (restartable)"
32.Sh LIBRARY
33.Lb libc
34.Sh SYNOPSIS
35.In wchar.h
36.Ft size_t
37.Fn mbrlen "const char *restrict s" "size_t n" "mbstate_t *restrict ps"
38.Sh DESCRIPTION
39The
40.Fn mbrlen
41function determines the the number of bytes constituting the
42multibyte character sequence pointer to by
43.Fa s .
44.Pp
45It is equivalent to:
46.Pp
47.Dl "mbrtowc(NULL, s, n, ps);"
48.Pp
49Except that when
50.Fa ps
51is a NULL pointer,
52.Fn mbrlen
53uses its own static, internal
54.Ft mbstate_t
55object to keep track of shift state.
56.Sh RETURN VALUES
57The
58.Fn mbrlen
59functions returns:
60.Bl -tag -width indent
61.It 0
62The first
63.Fa n
64or fewer bytes of
65.Fa s
66represent the null wide character (L'\e0').
67.It >0
68The first
69.Fa n
70or fewer bytes of
71.Fa s
72represent a valid character,
73.Fn mbrtowc
74returns the length (in bytes) of the multibyte sequence.
75.It Xo
76.No ( Ns
77.Ft size_t Ns
78.No ) Ns \&-2
79.Xc
80The first
81.Fa n
82bytes of
83.Fa s
84are an incomplete multibyte sequence.
85.It Xo
86.No ( Ns
87.Ft size_t Ns
88.No ) Ns \&-1
89.Xc
90The byte sequence pointed to by
91.Fa s
92is an invalid multibyte sequence.
93.El
94.Sh ERRORS
95The
96.Fn mbrlen
97function will fail if:
98.Bl -tag -width Er
99.\".It Bq Er EINVAL
100.\"Invalid argument.
101.It Bq Er EILSEQ
102An invalid multibyte sequence was detected.
103.El
104.Sh SEE ALSO
105.Xr mblen 3 ,
106.Xr mbrtowc 3
107.Sh STANDARDS
108The
109.Fn mbrlen
110function conforms to
111.St -isoC-99 .
112.Sh BUGS
113The current implementation does not support shift states.
114