1MBRTOWC(3) Linux Programmer's Manual MBRTOWC(3)
2
3
4
6 mbrtowc - convert a multibyte sequence to a wide character
7
9 #include <wchar.h>
10
11 size_t mbrtowc(wchar_t *pwc, const char *s, size_t n, mbstate_t *ps);
12
14 The main case for this function is when s is not NULL and pwc is not
15 NULL. In this case, the mbrtowc() function inspects at most n bytes of
16 the multibyte string starting at s, extracts the next complete multi‐
17 byte character, converts it to a wide character and stores it at *pwc.
18 It updates the shift state *ps. If the converted wide character is not
19 L'\0', it returns the number of bytes that were consumed from s. If
20 the converted wide character is L'\0', it resets the shift state *ps to
21 the initial state and returns 0.
22
23 If the n bytes starting at s do not contain a complete multibyte char‐
24 acter, mbrtowc() returns (size_t) -2. This can happen even if n >=
25 MB_CUR_MAX, if the multibyte string contains redundant shift sequences.
26
27 If the multibyte string starting at s contains an invalid multibyte
28 sequence before the next complete character, mbrtowc() returns
29 (size_t) -1 and sets errno to EILSEQ. In this case, the effects on *ps
30 are undefined.
31
32 A different case is when s is not NULL but pwc is NULL. In this case
33 the mbrtowc() function behaves as above, except that it does not store
34 the converted wide character in memory.
35
36 A third case is when s is NULL. In this case, pwc and n are ignored.
37 If the conversion state represented by *ps denotes an incomplete multi‐
38 byte character conversion, the mbrtowc() function returns (size_t) -1,
39 sets errno to EILSEQ, and leaves *ps in an undefined state. Otherwise,
40 the mbrtowc() function puts *ps in the initial state and returns 0.
41
42 In all of the above cases, if ps is a NULL pointer, a static anonymous
43 state only known to the mbrtowc function is used instead. Otherwise,
44 *ps must be a valid mbstate_t object. An mbstate_t object a can be
45 initialized to the initial state by zeroing it, for example using
46
47 memset(&a, 0, sizeof(a));
48
50 The mbrtowc() function returns the number of bytes parsed from the
51 multibyte sequence starting at s, if a non-L'\0' wide character was
52 recognized. It returns 0, if a L'\0' wide character was recognized.
53 It returns (size_t) -1 and sets errno to EILSEQ, if an invalid multi‐
54 byte sequence was encountered. It returns (size_t) -2 if it couldn't
55 parse a complete multibyte character, meaning that n should be
56 increased.
57
59 C99.
60
62 The behavior of mbrtowc() depends on the LC_CTYPE category of the cur‐
63 rent locale.
64
66 mbsrtowcs(3)
67
69 This page is part of release 3.22 of the Linux man-pages project. A
70 description of the project, and information about reporting bugs, can
71 be found at http://www.kernel.org/doc/man-pages/.
72
73
74
75GNU 2001-11-22 MBRTOWC(3)