| MBRLEN(3) | Library Functions Manual | MBRLEN(3) |
mbrlen — get
number of bytes in a multibyte character (restartable)
#include
<wchar.h>
size_t
mbrlen(const
char * restrict s, size_t
n, mbstate_t * restrict
ps);
The
mbrlen()
function returns the number of bytes in the first multibyte character of the
multibyte string s. It examines at most the first
n bytes of s.
mbrlen()
is equivalent to the following call, except that ps is
evaluated only once:
mbrtowc(NULL, s, n, (ps != NULL) ? ps : &internal);
Here, internal is an internal state object automatically initialized to the initial conversion state at startup time of the program.
In state-dependent encodings,
s may point to special sequence bytes changing the
shift state. Although such sequence bytes correspond to no wide character,
they affect the conversion state object pointed to by
ps, and
mbrlen()
treats the special sequence bytes as if they were part of the subsequent
multibyte character.
Unlike
mblen(3),
mbrlen()
accepts the byte sequence if it is not a complete character but the initial
part of some valid character. In this case, this function accepts all such
bytes and saves them into the conversion state object pointed to by
ps. They will be used on subsequent calls of this
function to restart the conversion suspended.
The behaviour of
mbrlen()
is affected by the LC_CTYPE category of the current
locale.
There are the special cases:
mbrlen()
sets the conversion state object pointed to by ps to
the initial conversion state and always returns 0. Unlike
mblen(3), the value returned
does not indicate whether the current encoding of the locale is
state-dependent.
In this case,
mbrlen()
ignores n.
mbrlen() always returns (size_t)-2.mbrlen() uses its own internal state object to
keep the conversion state instead of the ps
argument.
Calling any other function in
libc never
changes the internal state of
mbrlen(),
except for calling
setlocale(3) with an
LC_CTYPE that differs from the current locale.
Such setlocale(3) calls
cause the internal state of this function to become indeterminate.
The mbrlen() function returns:
MB_CUR_MAX macro.MB_CUR_MAX, this can only occur if
s contains a redundant shift sequence.mbrtowc() sets errno to
indicate the error.mbrlen() may cause an error in the
following cases:
The mbrlen() function conforms to ISO/IEC
9899/AMD1:1995 (“ISO C90, Amendment 1”). The restrict
qualifier is added at ISO/IEC 9899/1999 (“ISO C99”).
| March 29, 2022 | openbsd |