]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man3/mbsrtowcs.3
Many pages: Fix style issues reported by `make lint-groff`
[thirdparty/man-pages.git] / man3 / mbsrtowcs.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 http://www.UNIX-systems.org/online.html
fea681da
MK
9.\" ISO/IEC 9899:1999
10.\"
1d767b55 11.TH MBSRTOWCS 3 2021-03-22 "GNU" "Linux Programmer's Manual"
fea681da 12.SH NAME
d0f17b57 13mbsrtowcs \- convert a multibyte string to a wide-character string
14cd5e25
AC
14.SH LIBRARY
15Standard C library
8fc3b2cf 16.RI ( libc ", " \-lc )
fea681da
MK
17.SH SYNOPSIS
18.nf
19.B #include <wchar.h>
68e4db0a 20.PP
b4a5b818
AC
21.BI "size_t mbsrtowcs(wchar_t *restrict " dest ", const char **restrict " src ,
22.BI " size_t " len ", mbstate_t *restrict " ps );
fea681da
MK
23.fi
24.SH DESCRIPTION
40aa0db0
MK
25If
26.I dest
b437fdd9 27is not NULL, the
60a90ecd
MK
28.BR mbsrtowcs ()
29function converts the
40aa0db0
MK
30multibyte string
31.I *src
32to a wide-character string starting at
33.IR dest .
34At most
35.I len
36wide characters are written to
37.IR dest .
c13182ef 38The shift state
40aa0db0
MK
39.I *ps
40is updated.
c13182ef 41The conversion is effectively performed by repeatedly
657e762d 42calling
0daa9e92 43.I "mbrtowc(dest, *src, n, ps)"
40aa0db0
MK
44where
45.I n
46is some
fea681da 47positive number, as long as this call succeeds, and then incrementing
40aa0db0
MK
48.I dest
49by one and
50.I *src
51by the number of bytes consumed.
c13182ef 52The conversion can stop for three reasons:
bce5f0ae
MK
53.IP 1. 3
54An invalid multibyte sequence has been encountered.
d99f93e8 55In this case,
40aa0db0 56.I *src
7d2cb9d5 57is left pointing to the invalid multibyte sequence,
009df872 58.I (size_t)\ \-1
7d2cb9d5 59is returned,
40aa0db0
MK
60and
61.I errno
62is set to
63.BR EILSEQ .
bce5f0ae 64.IP 2.
40aa0db0 65.I len
d1a71985 66non-L\(aq\e0\(aq wide characters have been stored at
40aa0db0 67.IR dest .
d7e98586 68In this case,
40aa0db0
MK
69.I *src
70is left pointing to the next
d9a10d9d 71multibyte sequence to be converted,
40aa0db0
MK
72and the number of wide characters written to
73.I dest
74is returned.
bce5f0ae
MK
75.IP 3.
76The multibyte string has been completely converted, including the
d1a71985 77terminating null wide character (\(aq\e0\(aq), which has the side
40aa0db0
MK
78effect of bringing back
79.I *ps
80to the
e9c23bc6 81initial state.
d99f93e8 82In this case,
40aa0db0
MK
83.I *src
84is set to NULL, and the number of wide
85characters written to
86.IR dest ,
e9c23bc6 87excluding the terminating null wide character, is returned.
fea681da 88.PP
40aa0db0 89If
1ae6b2c7 90.I dest
40aa0db0
MK
91is NULL,
92.I len
93is ignored,
d9a10d9d
MK
94and the conversion proceeds as above,
95except that the converted wide characters are not written out to memory,
fea681da
MK
96and that no length limit exists.
97.PP
d9a10d9d 98In both of the above cases,
40aa0db0
MK
99if
100.I ps
b437fdd9 101is NULL, a static anonymous
33a0ccb2 102state known only to the
d9a10d9d
MK
103.BR mbsrtowcs ()
104function is used instead.
fea681da 105.PP
40aa0db0
MK
106The programmer must ensure that there is room for at least
107.I len
108wide
109characters at
110.IR dest .
47297adb 111.SH RETURN VALUE
60a90ecd
MK
112The
113.BR mbsrtowcs ()
114function returns the number of wide characters that make
d0f17b57 115up the converted part of the wide-character string, not including the
c13182ef
MK
116terminating null wide character.
117If an invalid multibyte sequence was
7d2cb9d5 118encountered,
009df872 119.I (size_t)\ \-1
40aa0db0
MK
120is returned, and
121.I errno
122set to
123.BR EILSEQ .
03c07cb1
ZL
124.SH ATTRIBUTES
125For an explanation of the terms used in this section, see
126.BR attributes (7).
c466875e
MK
127.ad l
128.nh
03c07cb1
ZL
129.TS
130allbox;
b32feea5 131lb lb lbx
03c07cb1
ZL
132l l l.
133Interface Attribute Value
134T{
135.BR mbsrtowcs ()
b32feea5
MK
136T} Thread safety T{
137MT-Unsafe race:mbsrtowcs/!ps
138T}
03c07cb1 139.TE
c466875e
MK
140.hy
141.ad
847e0d88 142.sp 1
47297adb 143.SH CONFORMING TO
765c9ca2 144POSIX.1-2001, POSIX.1-2008, C99.
fea681da 145.SH NOTES
d9bfdb9c 146The behavior of
60a90ecd 147.BR mbsrtowcs ()
1274071a
MK
148depends on the
149.B LC_CTYPE
150category of the
fea681da
MK
151current locale.
152.PP
40aa0db0
MK
153Passing NULL as
154.I ps
155is not multithread safe.
47297adb 156.SH SEE ALSO
e37e3282 157.BR iconv (3),
9247e95b 158.BR mbrtowc (3),
65789f05 159.BR mbsinit (3),
e37e3282
MK
160.BR mbsnrtowcs (3),
161.BR mbstowcs (3)