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