1MBRTOWC(3P) POSIX Programmer's Manual MBRTOWC(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 mbrtowc — convert a character to a wide-character code (restartable)
14
16 #include <wchar.h>
17
18 size_t mbrtowc(wchar_t *restrict pwc, const char *restrict s,
19 size_t n, mbstate_t *restrict ps);
20
22 The functionality described on this reference page is aligned with the
23 ISO C standard. Any conflict between the requirements described here
24 and the ISO C standard is unintentional. This volume of POSIX.1‐2008
25 defers to the ISO C standard.
26
27 If s is a null pointer, the mbrtowc() function shall be equivalent to
28 the call:
29
30 mbrtowc(NULL, "", 1, ps)
31
32 In this case, the values of the arguments pwc and n are ignored.
33
34 If s is not a null pointer, the mbrtowc() function shall inspect at
35 most n bytes beginning at the byte pointed to by s to determine the
36 number of bytes needed to complete the next character (including any
37 shift sequences). If the function determines that the next character is
38 completed, it shall determine the value of the corresponding wide char‐
39 acter and then, if pwc is not a null pointer, shall store that value in
40 the object pointed to by pwc. If the corresponding wide character is
41 the null wide character, the resulting state described shall be the
42 initial conversion state.
43
44 If ps is a null pointer, the mbrtowc() function shall use its own
45 internal mbstate_t object, which shall be initialized at program start-
46 up to the initial conversion state. Otherwise, the mbstate_t object
47 pointed to by ps shall be used to completely describe the current con‐
48 version state of the associated character sequence. The implementation
49 shall behave as if no function defined in this volume of POSIX.1‐2008
50 calls mbrtowc().
51
52 The behavior of this function is affected by the LC_CTYPE category of
53 the current locale.
54
55 The mbrtowc() function need not be thread-safe if called with a NULL ps
56 argument.
57
58 The mbrtowc() function shall not change the setting of errno if suc‐
59 cessful.
60
62 The mbrtowc() function shall return the first of the following that
63 applies:
64
65 0 If the next n or fewer bytes complete the character that
66 corresponds to the null wide character (which is the value
67 stored).
68
69 between 1 and n inclusive
70 If the next n or fewer bytes complete a valid character
71 (which is the value stored); the value returned shall be
72 the number of bytes that complete the character.
73
74 (size_t)−2 If the next n bytes contribute to an incomplete but poten‐
75 tially valid character, and all n bytes have been processed
76 (no value is stored). When n has at least the value of the
77 {MB_CUR_MAX} macro, this case can only occur if s points at
78 a sequence of redundant shift sequences (for implementa‐
79 tions with state-dependent encodings).
80
81 (size_t)−1 If an encoding error occurs, in which case the next n or
82 fewer bytes do not contribute to a complete and valid char‐
83 acter (no value is stored). In this case, [EILSEQ] shall be
84 stored in errno and the conversion state is undefined.
85
87 The mbrtowc() function shall fail if:
88
89 EILSEQ An invalid character sequence is detected.
90
91 The mbrtowc() function may fail if:
92
93 EINVAL ps points to an object that contains an invalid conversion
94 state.
95
96 The following sections are informative.
97
99 None.
100
102 None.
103
105 None.
106
108 None.
109
111 mbsinit(), mbsrtowcs()
112
113 The Base Definitions volume of POSIX.1‐2008, <wchar.h>
114
116 Portions of this text are reprinted and reproduced in electronic form
117 from IEEE Std 1003.1, 2013 Edition, Standard for Information Technology
118 -- Portable Operating System Interface (POSIX), The Open Group Base
119 Specifications Issue 7, Copyright (C) 2013 by the Institute of Electri‐
120 cal and Electronics Engineers, Inc and The Open Group. (This is
121 POSIX.1-2008 with the 2013 Technical Corrigendum 1 applied.) In the
122 event of any discrepancy between this version and the original IEEE and
123 The Open Group Standard, the original IEEE and The Open Group Standard
124 is the referee document. The original Standard can be obtained online
125 at http://www.unix.org/online.html .
126
127 Any typographical or formatting errors that appear in this page are
128 most likely to have been introduced during the conversion of the source
129 files to man page format. To report such errors, see https://www.ker‐
130 nel.org/doc/man-pages/reporting_bugs.html .
131
132
133
134IEEE/The Open Group 2013 MBRTOWC(3P)