]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man3/mbrtowc.3
Many pages: Use correct letter case in page titles (TH)
[thirdparty/man-pages.git] / man3 / mbrtowc.3
CommitLineData
fea681da
MK
1.\" Copyright (c) Bruno Haible <haible@clisp.cons.org>
2.\"
e4a74ca8 3.\" SPDX-License-Identifier: GPL-2.0-or-later
fea681da
MK
4.\"
5.\" References consulted:
6.\" GNU glibc-2 source code and manual
7.\" Dinkumware C library reference http://www.dinkumware.com/
008f1ecc 8.\" OpenGroup's Single UNIX specification
fea681da
MK
9.\" http://www.UNIX-systems.org/online.html
10.\" ISO/IEC 9899:1999
11.\"
4c1c5274 12.TH mbrtowc 3 (date) "Linux man-pages (unreleased)"
fea681da
MK
13.SH NAME
14mbrtowc \- convert a multibyte sequence to a wide character
310a1f8b
AC
15.SH LIBRARY
16Standard C library
8fc3b2cf 17.RI ( libc ", " \-lc )
fea681da
MK
18.SH SYNOPSIS
19.nf
20.B #include <wchar.h>
68e4db0a 21.PP
b0d2d2e0
AC
22.BI "size_t mbrtowc(wchar_t *restrict " pwc ", const char *restrict " s \
23", size_t " n ,
24.BI " mbstate_t *restrict " ps );
fea681da
MK
25.fi
26.SH DESCRIPTION
40aa0db0 27The main case for this function is when
1ae6b2c7 28.I s
40aa0db0
MK
29is not NULL and
30.I pwc
31is
c13182ef 32not NULL.
60a90ecd
MK
33In this case, the
34.BR mbrtowc ()
40aa0db0
MK
35function inspects at most
36.I n
37bytes of the multibyte string starting at
38.IR s ,
39extracts the next complete
fea681da 40multibyte character, converts it to a wide character and stores it at
40aa0db0
MK
41.IR *pwc .
42It updates the shift state
43.IR *ps .
c13182ef 44If the converted wide
d1a71985 45character is not L\(aq\e0\(aq (the null wide character),
e9c23bc6 46it returns the number of bytes that were consumed
40aa0db0
MK
47from
48.IR s .
d1a71985 49If the converted wide character is L\(aq\e0\(aq, it resets the shift
40aa0db0
MK
50state
51.I *ps
52to the initial state and returns 0.
fea681da 53.PP
40aa0db0 54If the
1ae6b2c7 55.I n
40aa0db0
MK
56bytes starting at
57.I s
58do not contain a complete multibyte
60a90ecd
MK
59character,
60.BR mbrtowc ()
40aa0db0
MK
61returns
62.IR "(size_t)\ \-2" .
c13182ef 63This can happen even if
40aa0db0
MK
64.I n
65>=
66.IR MB_CUR_MAX ,
67if the multibyte string contains redundant shift
fea681da
MK
68sequences.
69.PP
40aa0db0
MK
70If the multibyte string starting at
71.I s
72contains an invalid multibyte
60a90ecd
MK
73sequence before the next complete character,
74.BR mbrtowc ()
75returns
1ae6b2c7 76.I (size_t)\ \-1
40aa0db0
MK
77and sets
78.I errno
79to
80.BR EILSEQ .
c13182ef 81In this case,
40aa0db0
MK
82the effects on
83.I *ps
84are undefined.
fea681da 85.PP
40aa0db0 86A different case is when
1ae6b2c7 87.I s
40aa0db0
MK
88is not NULL but
89.I pwc
90is NULL.
90c3966f 91In this case, the
60a90ecd 92.BR mbrtowc ()
5633d88a 93function behaves as above, except that it does not
fea681da
MK
94store the converted wide character in memory.
95.PP
40aa0db0
MK
96A third case is when
97.I s
98is NULL.
99In this case,
1ae6b2c7 100.I pwc
40aa0db0
MK
101and
102.I n
103are
c13182ef 104ignored.
40aa0db0
MK
105If the conversion state represented by
106.I *ps
107denotes an
60a90ecd
MK
108incomplete multibyte character conversion, the
109.BR mbrtowc ()
110function
40aa0db0
MK
111returns
112.IR "(size_t)\ \-1" ,
113sets
114.I errno
115to
116.BR EILSEQ ,
117and
118leaves
119.I *ps
120in an undefined state.
60a90ecd
MK
121Otherwise, the
122.BR mbrtowc ()
123function
40aa0db0
MK
124puts
125.I *ps
126in the initial state and returns 0.
fea681da 127.PP
40aa0db0
MK
128In all of the above cases, if
129.I ps
b437fdd9 130is NULL, a static anonymous
a692b189
MK
131state known only to the
132.BR mbrtowc ()
133function is used instead.
40aa0db0 134Otherwise,
1ae6b2c7 135.I *ps
40aa0db0
MK
136must be a valid
137.I mbstate_t
138object.
139An
1ae6b2c7 140.I mbstate_t
40aa0db0
MK
141object
142.I a
143can be initialized to the initial state
fea681da 144by zeroing it, for example using
bdd915e2 145.PP
a6e2f128 146.in +4n
b9c93deb 147.EX
fea681da 148memset(&a, 0, sizeof(a));
bdd915e2 149.EE
a6e2f128 150.in
47297adb 151.SH RETURN VALUE
60a90ecd
MK
152The
153.BR mbrtowc ()
154function returns the number of bytes parsed from the
40aa0db0
MK
155multibyte sequence starting at
156.IR s ,
d1a71985 157if a non-L\(aq\e0\(aq wide character
fea681da 158was recognized.
d1a71985 159It returns 0, if a L\(aq\e0\(aq wide character was recognized.
7d2cb9d5 160It returns
009df872 161.I (size_t)\ \-1
40aa0db0
MK
162and sets
163.I errno
164to
165.BR EILSEQ ,
166if an invalid multibyte sequence was
c13182ef 167encountered.
40aa0db0 168It returns
51700fd7 169.I "(size_t)\ \-2"
40aa0db0
MK
170if it couldn't parse a complete multibyte
171character, meaning that
172.I n
173should be increased.
1ad7b089 174.SH ATTRIBUTES
5cf6a734
PH
175For an explanation of the terms used in this section, see
176.BR attributes (7).
c466875e
MK
177.ad l
178.nh
5cf6a734
PH
179.TS
180allbox;
c466875e 181lbx lb lb
5cf6a734
PH
182l l l.
183Interface Attribute Value
184T{
1ad7b089 185.BR mbrtowc ()
5cf6a734
PH
186T} Thread safety MT-Unsafe race:mbrtowc/!ps
187.TE
c466875e
MK
188.hy
189.ad
190.sp 1
3113c7f3 191.SH STANDARDS
c4576455 192POSIX.1-2001, POSIX.1-2008, C99.
fea681da 193.SH NOTES
d9bfdb9c 194The behavior of
60a90ecd 195.BR mbrtowc ()
1274071a
MK
196depends on the
197.B LC_CTYPE
198category of the
fea681da 199current locale.
47297adb 200.SH SEE ALSO
9247e95b 201.BR mbsinit (3),
e37e3282 202.BR mbsrtowcs (3)