1MBLEN(3P) POSIX Programmer's Manual MBLEN(3P)
2
3
4
6 This manual page is part of the POSIX Programmer's Manual. The Linux
7 implementation of this interface may differ (consult the corresponding
8 Linux manual page for details of Linux behavior), or the interface may
9 not be implemented on Linux.
10
11
13 mblen — get number of bytes in a character
14
16 #include <stdlib.h>
17
18 int mblen(const char *s, size_t n);
19
21 The functionality described on this reference page is aligned with the
22 ISO C standard. Any conflict between the requirements described here
23 and the ISO C standard is unintentional. This volume of POSIX.1‐2008
24 defers to the ISO C standard.
25
26 If s is not a null pointer, mblen() shall determine the number of bytes
27 constituting the character pointed to by s. Except that the shift
28 state of mbtowc() is not affected, it shall be equivalent to:
29
30 mbtowc((wchar_t *)0, s, n);
31
32 The implementation shall behave as if no function defined in this vol‐
33 ume of POSIX.1‐2008 calls mblen().
34
35 The behavior of this function is affected by the LC_CTYPE category of
36 the current locale. For a state-dependent encoding, this function shall
37 be placed into its initial state by a call for which its character
38 pointer argument, s, is a null pointer. Subsequent calls with s as
39 other than a null pointer shall cause the internal state of the func‐
40 tion to be altered as necessary. A call with s as a null pointer shall
41 cause this function to return a non-zero value if encodings have state
42 dependency, and 0 otherwise. If the implementation employs special
43 bytes to change the shift state, these bytes shall not produce separate
44 wide-character codes, but shall be grouped with an adjacent character.
45 Changing the LC_CTYPE category causes the shift state of this function
46 to be unspecified.
47
48 The mblen() function need not be thread-safe.
49
51 If s is a null pointer, mblen() shall return a non-zero or 0 value, if
52 character encodings, respectively, do or do not have state-dependent
53 encodings. If s is not a null pointer, mblen() shall either return 0
54 (if s points to the null byte), or return the number of bytes that con‐
55 stitute the character (if the next n or fewer bytes form a valid char‐
56 acter), or return −1 (if they do not form a valid character) and may
57 set errno to indicate the error. In no case shall the value returned
58 be greater than n or the value of the {MB_CUR_MAX} macro.
59
61 The mblen() function may fail if:
62
63 EILSEQ An invalid character sequence is detected.
64
65 The following sections are informative.
66
68 None.
69
71 None.
72
74 None.
75
77 None.
78
80 mbtowc(), mbstowcs(), wctomb(), wcstombs()
81
82 The Base Definitions volume of POSIX.1‐2008, <stdlib.h>
83
85 Portions of this text are reprinted and reproduced in electronic form
86 from IEEE Std 1003.1, 2013 Edition, Standard for Information Technology
87 -- Portable Operating System Interface (POSIX), The Open Group Base
88 Specifications Issue 7, Copyright (C) 2013 by the Institute of Electri‐
89 cal and Electronics Engineers, Inc and The Open Group. (This is
90 POSIX.1-2008 with the 2013 Technical Corrigendum 1 applied.) In the
91 event of any discrepancy between this version and the original IEEE and
92 The Open Group Standard, the original IEEE and The Open Group Standard
93 is the referee document. The original Standard can be obtained online
94 at http://www.unix.org/online.html .
95
96 Any typographical or formatting errors that appear in this page are
97 most likely to have been introduced during the conversion of the source
98 files to man page format. To report such errors, see https://www.ker‐
99 nel.org/doc/man-pages/reporting_bugs.html .
100
101
102
103IEEE/The Open Group 2013 MBLEN(3P)