]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man3/mbtowc.3
Removed trailing white space at end of lines
[thirdparty/man-pages.git] / man3 / mbtowc.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 http://www.UNIX-systems.org/online.html
fea681da
MK
14.\" ISO/IEC 9899:1999
15.\"
9ba01802 16.TH MBTOWC 3 2019-03-06 "GNU" "Linux Programmer's Manual"
fea681da
MK
17.SH NAME
18mbtowc \- convert a multibyte sequence to a wide character
19.SH SYNOPSIS
20.nf
21.B #include <stdlib.h>
68e4db0a 22.PP
fea681da
MK
23.BI "int mbtowc(wchar_t *" pwc ", const char *" s ", size_t " n );
24.fi
25.SH DESCRIPTION
40aa0db0 26The main case for this function is when
51700fd7 27.IR s
40aa0db0
MK
28is not NULL and
29.I pwc
30is
c13182ef 31not NULL.
60a90ecd
MK
32In this case, the
33.BR mbtowc ()
40aa0db0
MK
34function inspects at most
35.I n
36bytes of the multibyte string starting at
37.IR s ,
c13182ef 38extracts the next complete
fea681da 39multibyte character, converts it to a wide character and stores it at
40aa0db0 40.IR *pwc .
33a0ccb2 41It updates an internal shift state known only to the
d8165d5b 42.BR mbtowc ()
c13182ef 43function.
40aa0db0
MK
44If
45.I s
d1a71985 46does not point to a null byte (\(aq\e0\(aq), it returns the number
40aa0db0
MK
47of bytes that were consumed from
48.IR s ,
49otherwise it returns 0.
fea681da 50.PP
40aa0db0 51If the
51700fd7 52.IR n
40aa0db0
MK
53bytes starting at
54.I s
55do not contain a complete multibyte
60a90ecd
MK
56character, or if they contain an invalid multibyte sequence,
57.BR mbtowc ()
00e28710 58returns \-1.
40aa0db0
MK
59This can happen even if
60.I n
61>=
62.IR MB_CUR_MAX ,
fea681da
MK
63if the multibyte string contains redundant shift sequences.
64.PP
40aa0db0 65A different case is when
51700fd7 66.IR s
40aa0db0
MK
67is not NULL but
68.I pwc
69is NULL.
1b0b840d 70In this case, the
60a90ecd 71.BR mbtowc ()
5633d88a 72function behaves as above, except that it does not
fea681da
MK
73store the converted wide character in memory.
74.PP
40aa0db0
MK
75A third case is when
76.I s
77is NULL.
78In this case,
51700fd7 79.IR pwc
40aa0db0
MK
80and
81.I n
82are
c13182ef 83ignored.
60a90ecd
MK
84The
85.BR mbtowc ()
86function
008f1ecc 87.\" The Dinkumware doc and the Single UNIX specification say this, but
fea681da 88.\" glibc doesn't implement this.
c13182ef
MK
89resets the shift state, only known to this function,
90to the initial state, and
c7094399 91returns nonzero if the encoding has nontrivial shift state, or zero if the
fea681da 92encoding is stateless.
47297adb 93.SH RETURN VALUE
40aa0db0
MK
94If
95.I s
96is not NULL, the
60a90ecd
MK
97.BR mbtowc ()
98function returns the number of
40aa0db0
MK
99consumed bytes starting at
100.IR s ,
101or 0 if
102.I s
103points to a null byte,
fea681da
MK
104or \-1 upon failure.
105.PP
40aa0db0
MK
106If
107.I s
108is NULL, the
60a90ecd
MK
109.BR mbtowc ()
110function
c7094399 111returns nonzero if the encoding
c382a365 112has nontrivial shift state, or zero if the encoding is stateless.
447b280d
PH
113.SH ATTRIBUTES
114For an explanation of the terms used in this section, see
115.BR attributes (7).
116.TS
117allbox;
118lb lb lb
119l l l.
120Interface Attribute Value
121T{
122.BR mbtowc ()
9644042f 123T} Thread safety MT-Unsafe race
447b280d 124.TE
47297adb 125.SH CONFORMING TO
c28537ad 126POSIX.1-2001, POSIX.1-2008, C99.
fea681da 127.SH NOTES
d9bfdb9c 128The behavior of
60a90ecd 129.BR mbtowc ()
1274071a
MK
130depends on the
131.B LC_CTYPE
132category of the
fea681da
MK
133current locale.
134.PP
71fea607 135This function is not multithread safe.
60a90ecd
MK
136The function
137.BR mbrtowc (3)
138provides
fea681da 139a better interface to the same functionality.
47297adb 140.SH SEE ALSO
e37e3282 141.BR MB_CUR_MAX (3),
9247e95b 142.BR mblen (3),
e37e3282 143.BR mbrtowc (3),
9247e95b 144.BR mbstowcs (3),
2e94784d
MK
145.BR wcstombs (3),
146.BR wctomb (3)