1 .\" Copyright (c) Bruno Haible <haible@clisp.cons.org>
3 .\" %%%LICENSE_START(GPLv2+_DOC_ONEPARA)
4 .\" This is free documentation; you can redistribute it and/or
5 .\" modify it under the terms of the GNU General Public License as
6 .\" published by the Free Software Foundation; either version 2 of
7 .\" the License, or (at your option) any later version.
10 .\" References consulted:
11 .\" GNU glibc-2 source code and manual
12 .\" Dinkumware C library reference http://www.dinkumware.com/
13 .\" OpenGroup's Single UNIX specification
14 .\" http://www.UNIX-systems.org/online.html
17 .TH MBRTOWC 3 2021-03-22 "GNU" "Linux Programmer's Manual"
19 mbrtowc \- convert a multibyte sequence to a wide character
24 .BI "size_t mbrtowc(wchar_t *restrict " pwc ", const char *restrict " s \
26 .BI " mbstate_t *restrict " ps );
29 The main case for this function is when
37 function inspects at most
39 bytes of the multibyte string starting at
41 extracts the next complete
42 multibyte character, converts it to a wide character and stores it at
44 It updates the shift state
47 character is not L\(aq\e0\(aq (the null wide character),
48 it returns the number of bytes that were consumed
51 If the converted wide character is L\(aq\e0\(aq, it resets the shift
54 to the initial state and returns 0.
60 do not contain a complete multibyte
65 This can happen even if
69 if the multibyte string contains redundant shift
72 If the multibyte string starting at
74 contains an invalid multibyte
75 sequence before the next complete character,
88 A different case is when
95 function behaves as above, except that it does not
96 store the converted wide character in memory.
107 If the conversion state represented by
110 incomplete multibyte character conversion, the
114 .IR "(size_t)\ \-1" ,
122 in an undefined state.
128 in the initial state and returns 0.
130 In all of the above cases, if
132 is NULL, a static anonymous
133 state known only to the
135 function is used instead.
145 can be initialized to the initial state
146 by zeroing it, for example using
150 memset(&a, 0, sizeof(a));
156 function returns the number of bytes parsed from the
157 multibyte sequence starting at
159 if a non-L\(aq\e0\(aq wide character
161 It returns 0, if a L\(aq\e0\(aq wide character was recognized.
168 if an invalid multibyte sequence was
172 if it couldn't parse a complete multibyte
173 character, meaning that
177 For an explanation of the terms used in this section, see
185 Interface Attribute Value
188 T} Thread safety MT-Unsafe race:mbrtowc/!ps
194 POSIX.1-2001, POSIX.1-2008, C99.