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
12 mbrtowc - convert a character to a wide-character code (restartable)
13
15 #include <wchar.h>
16
17 size_t mbrtowc(wchar_t *restrict pwc, const char *restrict s,
18 size_t n, mbstate_t *restrict ps);
19
20
22 If s is a null pointer, the mbrtowc() function shall be equivalent to
23 the call:
24
25
26 mbrtowc(NULL, "", 1, ps)
27
28 In this case, the values of the arguments pwc and n are ignored.
29
30 If s is not a null pointer, the mbrtowc() function shall inspect at
31 most n bytes beginning at the byte pointed to by s to determine the
32 number of bytes needed to complete the next character (including any
33 shift sequences). If the function determines that the next character is
34 completed, it shall determine the value of the corresponding wide char‐
35 acter and then, if pwc is not a null pointer, shall store that value in
36 the object pointed to by pwc. If the corresponding wide character is
37 the null wide character, the resulting state described shall be the
38 initial conversion state.
39
40 If ps is a null pointer, the mbrtowc() function shall use its own
41 internal mbstate_t object, which shall be initialized at program start-
42 up to the initial conversion state. Otherwise, the mbstate_t object
43 pointed to by ps shall be used to completely describe the current con‐
44 version state of the associated character sequence. The implementation
45 shall behave as if no function defined in this volume of
46 IEEE Std 1003.1-2001 calls mbrtowc().
47
48 The behavior of this function is affected by the LC_CTYPE category of
49 the current locale.
50
52 The mbrtowc() function shall return the first of the following that
53 applies:
54
55 0 If the next n or fewer bytes complete the character that corre‐
56 sponds to the null wide character (which is the value stored).
57
58 between 1 and n inclusive
59
60 If the next n or fewer bytes complete a valid character (which
61 is the value stored); the value returned shall be the number of
62 bytes that complete the character.
63
64 (size_t)-2
65 If the next n bytes contribute to an incomplete but potentially
66 valid character, and all n bytes have been processed (no value
67 is stored). When n has at least the value of the {MB_CUR_MAX}
68 macro, this case can only occur if s points at a sequence of
69 redundant shift sequences (for implementations with state-depen‐
70 dent encodings).
71
72 (size_t)-1
73 If an encoding error occurs, in which case the next n or fewer
74 bytes do not contribute to a complete and valid character (no
75 value is stored). In this case, [EILSEQ] shall be stored in
76 errno and the conversion state is undefined.
77
78
80 The mbrtowc() function may fail if:
81
82 EINVAL ps points to an object that contains an invalid conversion
83 state.
84
85 EILSEQ Invalid character sequence is detected.
86
87
88 The following sections are informative.
89
91 None.
92
94 None.
95
97 None.
98
100 None.
101
103 mbsinit(), the Base Definitions volume of IEEE Std 1003.1-2001,
104 <wchar.h>
105
107 Portions of this text are reprinted and reproduced in electronic form
108 from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
109 -- Portable Operating System Interface (POSIX), The Open Group Base
110 Specifications Issue 6, Copyright (C) 2001-2003 by the Institute of
111 Electrical and Electronics Engineers, Inc and The Open Group. In the
112 event of any discrepancy between this version and the original IEEE and
113 The Open Group Standard, the original IEEE and The Open Group Standard
114 is the referee document. The original Standard can be obtained online
115 at http://www.opengroup.org/unix/online.html .
116
117
118
119IEEE/The Open Group 2003 MBRTOWC(3P)