April 2024 | ||||||
Mo | Tu | We | Th | Fr | Sa | Su |
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | 1 | 2 | 3 | 4 | 5 |
6 | 7 | 8 | 9 | 10 | 11 | 12 |
#include <wchar.h> size_t mbrtowc(wchar_t *pwc, const char *s, size_t n, mbstate_t *ps);
If the n bytes starting at s do not contain a complete multibyte character, mbrtowc() returns (size_t) -2. This can happen even if n >= MB_CUR_MAX, if the multibyte string contains redundant shift sequences.
If the multibyte string starting at s contains an invalid multibyte sequence before the next complete character, mbrtowc() returns (size_t) -1 and sets errno to EILSEQ. In this case, the effects on *ps are undefined.
A different case is when s is not NULL but pwc is NULL. In this case the mbrtowc() function behaves as above, except that it does not store the converted wide character in memory.
A third case is when s is NULL. In this case, pwc and n are ignored. If the conversion state represented by *ps denotes an incomplete multibyte character conversion, the mbrtowc() function returns (size_t) -1, sets errno to EILSEQ, and leaves *ps in an undefined state. Otherwise, the mbrtowc() function puts *ps in the initial state and returns 0.
In all of the above cases, if ps is a NULL pointer, a static anonymous state only known to the mbrtowc function is used instead. Otherwise, *ps must be a valid mbstate_t object. An mbstate_t object a can be initialized to the initial state by zeroing it, for example using