Name
mblen
Synopsis
Determines the length of a multibyte character, or whether the multibyte encoding is stateful
#include <stdlib.h> intmblen
( const char *s
, size_tmaxsize
);
The mblen()
function
determines the length in bytes of a multibyte character referenced
by its pointer argument. If the argument points to a valid multibyte
character, then mblen()
returns a
value greater than zero. If the argument points to a null character
('\0'
), then mblen()
returns 0. A return value of -1
indicates that the argument does not point to a valid multibyte
character, or that the multibyte character is longer than the
maximum size specified by the second argument. The LC_TYPE
category in the current locale
settings determines which byte sequences are valid multibyte
characters.
The second argument specifies a maximum byte length for the
multibyte character, and should not be greater than the value of the
symbolic constant MB_CUR_MAX
,
defined in stdlib.h.
If you pass mblen()
a null
pointer as the first argument, then the return value indicates
whether the current multibyte encoding is stateful. This behavior is
the same as that of mbtowc()
. If
mblen()
returns 0, then the
encoding is stateless. If it returns any other value, the encoding
is stateful; that is, the interpretation of a given byte sequence
may depend on the shift state.
Example
size_t mbsrcat( char * restrict s1, char * restrict s2, mbstate_t * restrict p_s1state, size_t n ) /* mbsrcat: multibyte string restartable concatenation. * Appends ...
Get C in a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.