]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man3/mbrtowc.3
getent.1, intro.1, time.1, _exit.2, _syscall.2, accept.2, access.2, acct.2, adjtimex...
[thirdparty/man-pages.git] / man3 / mbrtowc.3
CommitLineData
fea681da
MK
1.\" Copyright (c) Bruno Haible <haible@clisp.cons.org>
2.\"
3.\" This is free documentation; you can redistribute it and/or
4.\" modify it under the terms of the GNU General Public License as
5.\" published by the Free Software Foundation; either version 2 of
6.\" the License, or (at your option) any later version.
7.\"
8.\" References consulted:
9.\" GNU glibc-2 source code and manual
10.\" Dinkumware C library reference http://www.dinkumware.com/
008f1ecc 11.\" OpenGroup's Single UNIX specification
fea681da
MK
12.\" http://www.UNIX-systems.org/online.html
13.\" ISO/IEC 9899:1999
14.\"
e9c23bc6 15.TH MBRTOWC 3 2011-09-28 "GNU" "Linux Programmer's Manual"
fea681da
MK
16.SH NAME
17mbrtowc \- convert a multibyte sequence to a wide character
18.SH SYNOPSIS
19.nf
20.B #include <wchar.h>
21.sp
3d54a910
MK
22.BI "size_t mbrtowc(wchar_t *" pwc ", const char *" s ", size_t " n \
23", mbstate_t *" ps );
fea681da
MK
24.fi
25.SH DESCRIPTION
26The main case for this function is when \fIs\fP is not NULL and \fIpwc\fP is
c13182ef 27not NULL.
60a90ecd
MK
28In this case, the
29.BR mbrtowc ()
30function inspects at most \fIn\fP
fea681da
MK
31bytes of the multibyte string starting at \fIs\fP, extracts the next complete
32multibyte character, converts it to a wide character and stores it at
c13182ef
MK
33\fI*pwc\fP.
34It updates the shift state \fI*ps\fP.
35If the converted wide
e9c23bc6
MK
36character is not L\(aq\\0\(aq (the null wide character),
37it returns the number of bytes that were consumed
c13182ef 38from \fIs\fP.
f81fb444 39If the converted wide character is L\(aq\\0\(aq, it resets the shift
fea681da
MK
40state \fI*ps\fP to the initial state and returns 0.
41.PP
42If the \fIn\fP bytes starting at \fIs\fP do not contain a complete multibyte
60a90ecd
MK
43character,
44.BR mbrtowc ()
009df872 45returns \fI(size_t)\ \-2\fP.
c13182ef 46This can happen even if
fea681da
MK
47\fIn\fP >= \fIMB_CUR_MAX\fP, if the multibyte string contains redundant shift
48sequences.
49.PP
50If the multibyte string starting at \fIs\fP contains an invalid multibyte
60a90ecd
MK
51sequence before the next complete character,
52.BR mbrtowc ()
53returns
e17aa487 54\fI(size_t)\ \-1\fP and sets \fIerrno\fP to \fBEILSEQ\fP.
c13182ef 55In this case,
fea681da
MK
56the effects on \fI*ps\fP are undefined.
57.PP
c13182ef
MK
58A different case is when \fIs\fP is not NULL but \fIpwc\fP is NULL.
59In this
60a90ecd
MK
60case the
61.BR mbrtowc ()
5633d88a 62function behaves as above, except that it does not
fea681da
MK
63store the converted wide character in memory.
64.PP
c13182ef
MK
65A third case is when \fIs\fP is NULL.
66In this case, \fIpwc\fP and \fIn\fP are
67ignored.
68If the conversion state represented by \fI*ps\fP denotes an
60a90ecd
MK
69incomplete multibyte character conversion, the
70.BR mbrtowc ()
71function
e17aa487 72returns \fI(size_t)\ \-1\fP, sets \fIerrno\fP to \fBEILSEQ\fP, and
c13182ef 73leaves \fI*ps\fP in an undefined state.
60a90ecd
MK
74Otherwise, the
75.BR mbrtowc ()
76function
fea681da
MK
77puts \fI*ps\fP in the initial state and returns 0.
78.PP
79In all of the above cases, if \fIps\fP is a NULL pointer, a static anonymous
80state only known to the mbrtowc function is used instead.
d9a10d9d
MK
81Otherwise, \fI*ps\fP must be a valid \fImbstate_t\fP object.
82An \fImbstate_t\fP object \fIa\fP can be initialized to the initial state
fea681da
MK
83by zeroing it, for example using
84.sp
a6e2f128 85.in +4n
fea681da 86memset(&a, 0, sizeof(a));
a6e2f128 87.in
47297adb 88.SH RETURN VALUE
60a90ecd
MK
89The
90.BR mbrtowc ()
91function returns the number of bytes parsed from the
f81fb444 92multibyte sequence starting at \fIs\fP, if a non-L\(aq\\0\(aq wide character
fea681da 93was recognized.
f81fb444 94It returns 0, if a L\(aq\\0\(aq wide character was recognized.
7d2cb9d5 95It returns
009df872 96.I (size_t)\ \-1
dcec8eb5 97and sets \fIerrno\fP to \fBEILSEQ\fP, if an invalid multibyte sequence was
c13182ef 98encountered.
009df872 99It returns \fI(size_t)\ \-2\fP if it couldn't parse a complete multibyte
fea681da 100character, meaning that \fIn\fP should be increased.
47297adb 101.SH CONFORMING TO
44a2c328 102C99.
fea681da 103.SH NOTES
d9bfdb9c 104The behavior of
60a90ecd 105.BR mbrtowc ()
1274071a
MK
106depends on the
107.B LC_CTYPE
108category of the
fea681da 109current locale.
47297adb 110.SH SEE ALSO
e37e3282 111.BR mbsrtowcs (3)