]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man3/mbsnrtowcs.3
Many pages: Fix style issues reported by `make lint-groff`
[thirdparty/man-pages.git] / man3 / mbsnrtowcs.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 9.\"
1d767b55 10.TH MBSNRTOWCS 3 2021-03-22 "GNU" "Linux Programmer's Manual"
fea681da 11.SH NAME
d0f17b57 12mbsnrtowcs \- convert a multibyte string to a wide-character string
3ea71b81
AC
13.SH LIBRARY
14Standard C library
8fc3b2cf 15.RI ( libc ", " \-lc )
fea681da
MK
16.SH SYNOPSIS
17.nf
18.B #include <wchar.h>
68e4db0a 19.PP
68802a1e
AC
20.BI "size_t mbsnrtowcs(wchar_t *restrict " dest ", const char **restrict " src ,
21.BI " size_t " nms ", size_t " len \
22", mbstate_t *restrict " ps );
fea681da 23.fi
68e4db0a 24.PP
d39ad78f 25.RS -4
7dbff9b4
MK
26Feature Test Macro Requirements for glibc (see
27.BR feature_test_macros (7)):
d39ad78f 28.RE
68e4db0a 29.PP
7dbff9b4 30.BR mbsnrtowcs ():
9d2adbae
MK
31.nf
32 Since glibc 2.10:
5c10d2c5 33 _POSIX_C_SOURCE >= 200809L
9d2adbae
MK
34 Before glibc 2.10:
35 _GNU_SOURCE
36.fi
fea681da 37.SH DESCRIPTION
60a90ecd
MK
38The
39.BR mbsnrtowcs ()
40function is like the
3a72373c 41.BR mbsrtowcs (3)
60a90ecd 42function, except that
40aa0db0
MK
43the number of bytes to be converted, starting at
44.IR *src ,
9caecea1 45is limited to at most
1ae6b2c7 46.I nms
9caecea1 47bytes.
fea681da 48.PP
40aa0db0
MK
49If
50.I dest
b437fdd9 51is not NULL, the
60a90ecd
MK
52.BR mbsnrtowcs ()
53function converts at
40aa0db0
MK
54most
55.I nms
56bytes from the
57multibyte string
58.I *src
59to a wide-character string starting at
60.IR dest .
61At most
62.I len
63wide characters are written to
64.IR dest .
c13182ef 65The shift state
40aa0db0
MK
66.I *ps
67is updated.
c13182ef 68The conversion is effectively performed by repeatedly
657e762d 69calling
0daa9e92 70.I "mbrtowc(dest, *src, n, ps)"
40aa0db0
MK
71where
72.I n
73is some
fea681da 74positive number, as long as this call succeeds, and then incrementing
40aa0db0
MK
75.I dest
76by one and
77.I *src
78by the number of bytes consumed.
c13182ef 79The
fea681da 80conversion can stop for three reasons:
bce5f0ae 81.IP 1. 3
bd0914f3 82An invalid multibyte sequence has been encountered.
a8204fda 83In this case,
40aa0db0 84.I *src
7d2cb9d5 85is left pointing to the invalid multibyte sequence,
009df872 86.I (size_t)\ \-1
7d2cb9d5 87is returned,
40aa0db0
MK
88and
89.I errno
90is set to
91.BR EILSEQ .
bce5f0ae 92.IP 2.
40aa0db0
MK
93The
94.I nms
95limit forces a stop,
96or
97.I len
d1a71985 98non-L\(aq\e0\(aq wide characters
40aa0db0
MK
99have been stored at
100.IR dest .
a8204fda 101In this case,
40aa0db0
MK
102.I *src
103is left pointing to the
fea681da 104next multibyte sequence to be converted, and the number of wide characters
40aa0db0
MK
105written to
106.I dest
107is returned.
bce5f0ae
MK
108.IP 3.
109The multibyte string has been completely converted, including the
d1a71985 110terminating null wide character (\(aq\e0\(aq)
40aa0db0
MK
111(which has the side effect of bringing back
112.I *ps
113to the
c13182ef 114initial state).
a8204fda 115In this case,
40aa0db0
MK
116.I *src
117is set to NULL, and the number of wide
118characters written to
119.IR dest ,
e9c23bc6 120excluding the terminating null wide character,
fea681da
MK
121is returned.
122.PP
5b711f5e
MK
123According to POSIX.1,
124if the input buffer ends with an incomplete character,
125it is unspecified whether conversion stops at the end of
126the previous character (if any), or at the end of the input buffer.
127The glibc implementation adopts the former behavior.
847e0d88 128.PP
40aa0db0 129If
1ae6b2c7 130.I dest
40aa0db0
MK
131is NULL,
132.I len
133is ignored, and the conversion proceeds as
fbe183be
MK
134above, except that the converted wide characters
135are not written out to memory,
fea681da
MK
136and that no destination length limit exists.
137.PP
40aa0db0
MK
138In both of the above cases, if
139.I ps
b437fdd9 140is NULL, a static anonymous
7b3a353f
MK
141state known only to the
142.BR mbsnrtowcs ()
143function is used instead.
fea681da 144.PP
40aa0db0
MK
145The programmer must ensure that there is room for at least
146.I len
147wide
148characters at
149.IR dest .
47297adb 150.SH RETURN VALUE
60a90ecd
MK
151The
152.BR mbsnrtowcs ()
153function returns the number of wide characters
d0f17b57 154that make up the converted part of the wide-character string,
fbe183be 155not including the terminating null wide character.
c13182ef 156If an invalid multibyte sequence was
7d2cb9d5 157encountered,
009df872 158.I (size_t)\ \-1
40aa0db0
MK
159is returned, and
160.I errno
161set to
162.BR EILSEQ .
adad095f
ZL
163.SH ATTRIBUTES
164For an explanation of the terms used in this section, see
165.BR attributes (7).
c466875e
MK
166.ad l
167.nh
adad095f
ZL
168.TS
169allbox;
b32feea5 170lb lb lbx
adad095f
ZL
171l l l.
172Interface Attribute Value
173T{
174.BR mbsnrtowcs ()
b32feea5
MK
175T} Thread safety T{
176MT-Unsafe race:mbsnrtowcs/!ps
177T}
adad095f 178.TE
c466875e
MK
179.hy
180.ad
847e0d88 181.sp 1
47297adb 182.SH CONFORMING TO
d9a8bda4 183POSIX.1-2008.
fea681da 184.SH NOTES
d9bfdb9c 185The behavior of
60a90ecd 186.BR mbsnrtowcs ()
1274071a
MK
187depends on the
188.B LC_CTYPE
189category of the
fea681da
MK
190current locale.
191.PP
40aa0db0
MK
192Passing NULL as
193.I ps
194is not multithread safe.
47297adb 195.SH SEE ALSO
e37e3282 196.BR iconv (3),
bba4bbbd 197.BR mbrtowc (3),
9247e95b 198.BR mbsinit (3),
e37e3282 199.BR mbsrtowcs (3)