1mbrtowc(3C)              Standard C Library Functions              mbrtowc(3C)
2
3
4

NAME

6       mbrtowc - convert a character to a wide-character code (restartable)
7

SYNOPSIS

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

DESCRIPTION

16       If  s  is  a  null pointer, the mbrtowc() function is equivalent to the
17       call:
18
19         mbrtowc(NULL, ``'', 1, ps)
20
21
22
23       In this case, the values of the arguments pwc and n are ignored.
24
25
26       If s is not a null pointer, the mbrtowc() function inspects at  most  n
27       bytes beginning at the byte pointed to by  s to determine the number of
28       bytes needed to complete  the  next   character  (including  any  shift
29       sequences).  If the function determines that the next character is com‐
30       pleted, it determines the value of the corresponding wide-character and
31       then,  if  pwc  is  not a null pointer, stores that value in the object
32       pointed to by pwc. If the  corresponding  wide-character  is  the  null
33       wide-character, the resulting state described is the initial conversion
34       state.
35
36
37       If ps is a null pointer, the mbrtowc() function uses its  own  internal
38       mbstate_t  object,  which is initialized at program startup to the ini‐
39       tial conversion state.   Otherwise, the  mbstate_t object pointed to by
40       ps  is  used to completely describe the current conversion state of the
41       associated character sequence. Solaris will behave as  if  no  function
42       defined in the Solaris Reference Manual calls mbrtowc().
43
44
45       The  behavior  of this function is affected by the LC_CTYPE category of
46       the current locale.  See environ(5).
47

RETURN VALUES

49       The mbrtowc() function returns the first of the following that applies:
50
51       0                If the next n or fewer bytes  complete  the  character
52                        that  corresponds to the null wide-character (which is
53                        the value stored).
54
55
56       positive         If the next n or fewer bytes complete a valid  charac‐
57                        ter (which is the value stored); the value returned is
58                        the number of bytes that complete the character.
59
60
61       (size_t)−2       If the next n bytes contribute to  an  incomplete  but
62                        potentially  valid   character,  and  all n bytes have
63                        been processed (no value is stored).   When n  has  at
64                        least the value of the MB_CUR_MAX macro, this case can
65                        only occur if  s points at  a  sequence  of  redundant
66                        shift sequences (for implementations with state-depen‐
67                        dent encodings).
68
69
70       (size_t)−1       If an encoding error occurs, in which case the next  n
71                        or  fewer  bytes  do  not contribute to a complete and
72                        valid  character (no value is stored).  In this  case,
73                        EILSEQ  is stored in errno and the conversion state is
74                        undefined.
75
76

ERRORS

78       The mbrtowc() function may fail if:
79
80       EINVAL    The ps argument points to an object that contains an  invalid
81                 conversion state.
82
83
84       EILSEQ    Invalid character sequence is detected.
85
86

ATTRIBUTES

88       See attributes(5) for descriptions of the following attributes:
89
90
91
92
93       ┌─────────────────────────────┬─────────────────────────────┐
94       │      ATTRIBUTE TYPE         │      ATTRIBUTE VALUE        │
95       ├─────────────────────────────┼─────────────────────────────┤
96       │Interface Stability          │Standard                     │
97       ├─────────────────────────────┼─────────────────────────────┤
98       │MT-Level                     │See NOTES below              │
99       └─────────────────────────────┴─────────────────────────────┘
100

SEE ALSO

102       mbsinit(3C), setlocale(3C), attributes(5), environ(5), standards(5)
103

NOTES

105       If  ps  is  not  a  null  pointer,  mbrtowc() uses the mbstate_t object
106       pointed to by ps and the function can be used safely  in  multithreaded
107       applications,  as  long  as setlocale(3C) is not being called to change
108       the locale. If ps is  a  null  pointer,  mbrtowc()  uses  its  internal
109       mbstate_t  object  and the function is Unsafe in multithreaded applica‐
110       tions.
111
112
113
114SunOS 5.11                        1 Nov 2003                       mbrtowc(3C)
Impressum