1MBRTOWC(3)                 Linux Programmer's Manual                MBRTOWC(3)
2
3
4

NAME

6       mbrtowc - convert a multibyte sequence to a wide character
7

SYNOPSIS

9       #include <wchar.h>
10
11       size_t mbrtowc(wchar_t *pwc, const char *s, size_t n, mbstate_t *ps);
12

DESCRIPTION

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 the
20       converted wide character is L'\0', it resets the shift state *ps to the
21       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, excepts 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. If
37       the conversion state represented by *ps denotes an incomplete multibyte
38       character conversion, the mbrtowc() function returns (size_t)(-1), sets
39       errno to EILSEQ, and leaves *ps in an undefined state.  Otherwise,  the
40       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

RETURN VALUE

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

CONFORMING TO

59       C99
60

SEE ALSO

62       mbsrtowcs(3)
63

NOTES

65       The behaviour of mbrtowc() depends on the LC_CTYPE category of the cur‐
66       rent locale.
67
68
69
70GNU                               2001-11-22                        MBRTOWC(3)
Impressum