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 NULL, a static anonymous state
43       known only to the mbrtowc() function is used instead.   Otherwise,  *ps
44       must  be  a  valid mbstate_t object.  An mbstate_t object a can be ini‐
45       tialized 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       For  an  explanation  of  the  terms  used   in   this   section,   see
60       attributes(7).
61
62       ┌──────────┬───────────────┬────────────────────────────┐
63Interface Attribute     Value                      
64       ├──────────┼───────────────┼────────────────────────────┤
65mbrtowc() │ Thread safety │ MT-Unsafe race:mbrtowc/!ps │
66       └──────────┴───────────────┴────────────────────────────┘

CONFORMING TO

68       POSIX.1-2001, POSIX.1-2008, C99.
69

NOTES

71       The  behavior of mbrtowc() depends on the LC_CTYPE category of the cur‐
72       rent locale.
73

SEE ALSO

75       mbsinit(3), mbsrtowcs(3)
76

COLOPHON

78       This page is part of release 5.02 of the Linux  man-pages  project.   A
79       description  of  the project, information about reporting bugs, and the
80       latest    version    of    this    page,    can     be     found     at
81       https://www.kernel.org/doc/man-pages/.
82
83
84
85GNU                               2019-03-06                        MBRTOWC(3)
Impressum