1mblen(3) Library Functions Manual mblen(3)
2
3
4
6 mblen - determine number of bytes in next multibyte character
7
9 Standard C library (libc, -lc)
10
12 #include <stdlib.h>
13
14 int mblen(const char s[.n], size_t n);
15
17 If s is not NULL, the mblen() function inspects at most n bytes of the
18 multibyte string starting at s and extracts the next complete multibyte
19 character. It uses a static anonymous shift state known only to the
20 mblen() function. If the multibyte character is not the null wide
21 character, it returns the number of bytes that were consumed from s.
22 If the multibyte character is the null wide character, it returns 0.
23
24 If the n bytes starting at s do not contain a complete multibyte char‐
25 acter, mblen() returns -1. This can happen even if n is greater than
26 or equal to MB_CUR_MAX, if the multibyte string contains redundant
27 shift sequences.
28
29 If the multibyte string starting at s contains an invalid multibyte se‐
30 quence before the next complete character, mblen() also returns -1.
31
32 If s is NULL, the mblen() function resets the shift state, known to
33 only this function, to the initial state, and returns nonzero if the
34 encoding has nontrivial shift state, or zero if the encoding is state‐
35 less.
36
38 The mblen() function returns the number of bytes parsed from the multi‐
39 byte sequence starting at s, if a non-null wide character was recog‐
40 nized. It returns 0, if a null wide character was recognized. It re‐
41 turns -1, if an invalid multibyte sequence was encountered or if it
42 couldn't parse a complete multibyte character.
43
45 For an explanation of the terms used in this section, see at‐
46 tributes(7).
47
48 ┌─────────────────────────────────────┬───────────────┬────────────────┐
49 │Interface │ Attribute │ Value │
50 ├─────────────────────────────────────┼───────────────┼────────────────┤
51 │mblen() │ Thread safety │ MT-Unsafe race │
52 └─────────────────────────────────────┴───────────────┴────────────────┘
53
55 The function mbrlen(3) provides a better interface to the same
56 functionality.
57
59 C11, POSIX.1-2008.
60
62 POSIX.1-2001, C99.
63
65 The behavior of mblen() depends on the LC_CTYPE category of the current
66 locale.
67
69 mbrlen(3)
70
71
72
73Linux man-pages 6.05 2023-07-20 mblen(3)