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' (the null wide character), it returns the number  of  bytes  that
20       were  consumed  from  s.   If the converted wide character is L'\0', it
21       resets the shift state *ps to 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 known only 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

ATTRIBUTES

59   Multithreading (see pthreads(7))
60       The mbrtowc() function is  thread-safe  with  exceptions.   It  is  not
61       thread-safe if called with a NULL ps parameter.
62

CONFORMING TO

64       C99.
65

NOTES

67       The  behavior of mbrtowc() depends on the LC_CTYPE category of the cur‐
68       rent locale.
69

SEE ALSO

71       mbsrtowcs(3)
72

COLOPHON

74       This page is part of release 3.53 of the Linux  man-pages  project.   A
75       description  of  the project, and information about reporting bugs, can
76       be found at http://www.kernel.org/doc/man-pages/.
77
78
79
80GNU                               2013-06-21                        MBRTOWC(3)
Impressum