1MBTOWC(3P)                 POSIX Programmer's Manual                MBTOWC(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
11

NAME

13       mbtowc — convert a character to a wide-character code
14

SYNOPSIS

16       #include <stdlib.h>
17
18       int mbtowc(wchar_t *restrict pwc, const char *restrict s, size_t n);
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‐2008
24       defers to the ISO C standard.
25
26       If  s  is  not  a  null pointer, mbtowc() shall determine the number of
27       bytes that constitute the character pointed to by  s.   It  shall  then
28       determine  the  wide-character  code for the value of type wchar_t that
29       corresponds to that character. (The value of  the  wide-character  code
30       corresponding to the null byte is 0.) If the character is valid and pwc
31       is not a null pointer, mbtowc() shall store the wide-character code  in
32       the object pointed to by pwc.
33
34       The  behavior  of this function is affected by the LC_CTYPE category of
35       the current locale. For a state-dependent encoding,  this  function  is
36       placed into its initial state by a call for which its character pointer
37       argument, s, is a null pointer. Subsequent calls with s as other than a
38       null  pointer  shall  cause  the  internal  state of the function to be
39       altered as necessary. A call with s as a null pointer shall cause  this
40       function to return a non-zero value if encodings have state dependency,
41       and 0 otherwise. If the implementation employs special bytes to  change
42       the  shift state, these bytes shall not produce separate wide-character
43       codes, but shall be grouped with an adjacent  character.  Changing  the
44       LC_CTYPE category causes the shift state of this function to be unspec‐
45       ified. At most n bytes of the array pointed to by s shall be examined.
46
47       The implementation shall behave as if no function defined in this  vol‐
48       ume of POSIX.1‐2008 calls mbtowc().
49
50       The mbtowc() function need not be thread-safe.
51

RETURN VALUE

53       If s is a null pointer, mbtowc() shall return a non-zero or 0 value, if
54       character encodings, respectively, do or do  not  have  state-dependent
55       encodings.  If  s is not a null pointer, mbtowc() shall either return 0
56       (if s points to the null byte), or return the number of bytes that con‐
57       stitute  the  converted  character (if the next n or fewer bytes form a
58       valid character), or return −1 and shall  set  errno  to  indicate  the
59       error (if they do not form a valid character).
60
61       In  no  case shall the value returned be greater than n or the value of
62       the {MB_CUR_MAX} macro.
63

ERRORS

65       The mbtowc() function shall fail if:
66
67       EILSEQ An invalid character sequence is detected.
68
69       The following sections are informative.
70

EXAMPLES

72       None.
73

APPLICATION USAGE

75       None.
76

RATIONALE

78       None.
79

FUTURE DIRECTIONS

81       None.
82

SEE ALSO

84       mblen(), mbstowcs(), wctomb(), wcstombs()
85
86       The Base Definitions volume of POSIX.1‐2008, <stdlib.h>
87
89       Portions of this text are reprinted and reproduced in  electronic  form
90       from IEEE Std 1003.1, 2013 Edition, Standard for Information Technology
91       -- Portable Operating System Interface (POSIX),  The  Open  Group  Base
92       Specifications Issue 7, Copyright (C) 2013 by the Institute of Electri‐
93       cal and Electronics Engineers,  Inc  and  The  Open  Group.   (This  is
94       POSIX.1-2008  with  the  2013  Technical Corrigendum 1 applied.) In the
95       event of any discrepancy between this version and the original IEEE and
96       The  Open Group Standard, the original IEEE and The Open Group Standard
97       is the referee document. The original Standard can be  obtained  online
98       at http://www.unix.org/online.html .
99
100       Any  typographical  or  formatting  errors that appear in this page are
101       most likely to have been introduced during the conversion of the source
102       files  to  man page format. To report such errors, see https://www.ker
103       nel.org/doc/man-pages/reporting_bugs.html .
104
105
106
107IEEE/The Open Group                  2013                           MBTOWC(3P)
Impressum