1MBRTOWC(3P)                POSIX Programmer's Manual               MBRTOWC(3P)
2
3
4

PROLOG

6       This  manual  page is part of the POSIX Programmer's Manual.  The Linux
7       implementation of this interface may differ (consult the  corresponding
8       Linux  manual page for details of Linux behavior), or the interface may
9       not be implemented on Linux.
10

NAME

12       mbrtowc — convert a character to a wide-character code (restartable)
13

SYNOPSIS

15       #include <wchar.h>
16
17       size_t mbrtowc(wchar_t *restrict pwc, const char *restrict s,
18           size_t n, mbstate_t *restrict ps);
19

DESCRIPTION

21       The functionality described on this reference page is aligned with  the
22       ISO C  standard.  Any  conflict between the requirements described here
23       and the ISO C standard is unintentional. This  volume  of  POSIX.1‐2017
24       defers to the ISO C standard.
25
26       If  s  is a null pointer, the mbrtowc() function shall be equivalent to
27       the call:
28
29
30           mbrtowc(NULL, "", 1, ps)
31
32       In this case, the values of the arguments pwc and n are ignored.
33
34       If s is not a null pointer, the mbrtowc()  function  shall  inspect  at
35       most  n  bytes  beginning  at the byte pointed to by s to determine the
36       number of bytes needed to complete the next  character  (including  any
37       shift sequences). If the function determines that the next character is
38       completed, it shall determine the value of the corresponding wide char‐
39       acter and then, if pwc is not a null pointer, shall store that value in
40       the object pointed to by pwc.  If the corresponding wide  character  is
41       the  null  wide  character,  the resulting state described shall be the
42       initial conversion state.
43
44       If ps is a null pointer, the  mbrtowc()  function  shall  use  its  own
45       internal mbstate_t object, which shall be initialized at program start-
46       up to the initial conversion state.  Otherwise,  the  mbstate_t  object
47       pointed  to by ps shall be used to completely describe the current con‐
48       version state of the associated character sequence. The  implementation
49       shall  behave  as if no function defined in this volume of POSIX.1‐2017
50       calls mbrtowc().
51
52       The behavior of this function is affected by the LC_CTYPE  category  of
53       the current locale.
54
55       The mbrtowc() function need not be thread-safe if called with a NULL ps
56       argument.
57
58       The mbrtowc() function shall not change the setting of  errno  if  suc‐
59       cessful.
60

RETURN VALUE

62       The  mbrtowc()  function  shall  return the first of the following that
63       applies:
64
65       0           If the next n or fewer bytes complete  the  character  that
66                   corresponds  to the null wide character (which is the value
67                   stored).
68
69       between 1 and n inclusive
70                   If the next n or fewer bytes  complete  a  valid  character
71                   (which  is  the  value stored); the value returned shall be
72                   the number of bytes that complete the character.
73
74       (size_t)-2  If the next n bytes contribute to an incomplete but  poten‐
75                   tially valid character, and all n bytes have been processed
76                   (no value is stored). When n has at least the value of  the
77                   {MB_CUR_MAX} macro, this case can only occur if s points at
78                   a sequence of redundant shift  sequences  (for  implementa‐
79                   tions with state-dependent encodings).
80
81       (size_t)-1  If  an  encoding  error occurs, in which case the next n or
82                   fewer bytes do not contribute to a complete and valid char‐
83                   acter (no value is stored). In this case, [EILSEQ] shall be
84                   stored in errno and the conversion state is undefined.
85

ERRORS

87       The mbrtowc() function shall fail if:
88
89       EILSEQ An invalid character sequence is detected.  In the POSIX  locale
90              an  [EILSEQ]  error cannot occur since all byte values are valid
91              characters.
92
93       The mbrtowc() function may fail if:
94
95       EINVAL ps points to an  object  that  contains  an  invalid  conversion
96              state.
97
98       The following sections are informative.
99

EXAMPLES

101       None.
102

APPLICATION USAGE

104       None.
105

RATIONALE

107       None.
108

FUTURE DIRECTIONS

110       None.
111

SEE ALSO

113       mbsinit(), mbsrtowcs()
114
115       The Base Definitions volume of POSIX.1‐2017, <wchar.h>
116
118       Portions  of  this text are reprinted and reproduced in electronic form
119       from IEEE Std 1003.1-2017, Standard for Information Technology --  Por‐
120       table  Operating System Interface (POSIX), The Open Group Base Specifi‐
121       cations Issue 7, 2018 Edition, Copyright (C) 2018 by the  Institute  of
122       Electrical  and  Electronics Engineers, Inc and The Open Group.  In the
123       event of any discrepancy between this version and the original IEEE and
124       The  Open Group Standard, the original IEEE and The Open Group Standard
125       is the referee document. The original Standard can be  obtained  online
126       at http://www.opengroup.org/unix/online.html .
127
128       Any  typographical  or  formatting  errors that appear in this page are
129       most likely to have been introduced during the conversion of the source
130       files  to  man page format. To report such errors, see https://www.ker
131       nel.org/doc/man-pages/reporting_bugs.html .
132
133
134
135IEEE/The Open Group                  2017                          MBRTOWC(3P)
Impressum