1MBTOWC(3P) POSIX Programmer's Manual MBTOWC(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
12 mbtowc — convert a character to a wide-character code
13
15 #include <stdlib.h>
16
17 int mbtowc(wchar_t *restrict pwc, const char *restrict s, size_t n);
18
20 The functionality described on this reference page is aligned with the
21 ISO C standard. Any conflict between the requirements described here
22 and the ISO C standard is unintentional. This volume of POSIX.1‐2017
23 defers to the ISO C standard.
24
25 If s is not a null pointer, mbtowc() shall determine the number of
26 bytes that constitute the character pointed to by s. It shall then
27 determine the wide-character code for the value of type wchar_t that
28 corresponds to that character. (The value of the wide-character code
29 corresponding to the null byte is 0.) If the character is valid and pwc
30 is not a null pointer, mbtowc() shall store the wide-character code in
31 the object pointed to by pwc.
32
33 The behavior of this function is affected by the LC_CTYPE category of
34 the current locale. For a state-dependent encoding, this function is
35 placed into its initial state by a call for which its character pointer
36 argument, s, is a null pointer. Subsequent calls with s as other than a
37 null pointer shall cause the internal state of the function to be
38 altered as necessary. A call with s as a null pointer shall cause this
39 function to return a non-zero value if encodings have state dependency,
40 and 0 otherwise. If the implementation employs special bytes to change
41 the shift state, these bytes shall not produce separate wide-character
42 codes, but shall be grouped with an adjacent character. Changing the
43 LC_CTYPE category causes the shift state of this function to be unspec‐
44 ified. At most n bytes of the array pointed to by s shall be examined.
45
46 The implementation shall behave as if no function defined in this vol‐
47 ume of POSIX.1‐2017 calls mbtowc().
48
49 The mbtowc() function need not be thread-safe.
50
52 If s is a null pointer, mbtowc() shall return a non-zero or 0 value, if
53 character encodings, respectively, do or do not have state-dependent
54 encodings. If s is not a null pointer, mbtowc() shall either return 0
55 (if s points to the null byte), or return the number of bytes that con‐
56 stitute the converted character (if the next n or fewer bytes form a
57 valid character), or return -1 and shall set errno to indicate the
58 error (if they do not form a valid character).
59
60 In no case shall the value returned be greater than n or the value of
61 the {MB_CUR_MAX} macro.
62
64 The mbtowc() function shall fail if:
65
66 EILSEQ An invalid character sequence is detected. In the POSIX locale
67 an [EILSEQ] error cannot occur since all byte values are valid
68 characters.
69
70 The following sections are informative.
71
73 None.
74
76 None.
77
79 None.
80
82 None.
83
85 mblen(), mbstowcs(), wctomb(), wcstombs()
86
87 The Base Definitions volume of POSIX.1‐2017, <stdlib.h>
88
90 Portions of this text are reprinted and reproduced in electronic form
91 from IEEE Std 1003.1-2017, Standard for Information Technology -- Por‐
92 table Operating System Interface (POSIX), The Open Group Base Specifi‐
93 cations Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of
94 Electrical and Electronics Engineers, Inc and The Open Group. In the
95 event of any discrepancy between this version and the original IEEE and
96 The Open Group Standard, the original IEEE and The Open Group Standard
97 is the referee document. The original Standard can be obtained online
98 at http://www.opengroup.org/unix/online.html .
99
100 Any typographical or formatting errors that appear in this page are
101 most likely to have been introduced during the conversion of the source
102 files to man page format. To report such errors, see https://www.ker‐
103 nel.org/doc/man-pages/reporting_bugs.html .
104
105
106
107IEEE/The Open Group 2017 MBTOWC(3P)