]>
Commit | Line | Data |
---|---|---|
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 | 12 | mbsnrtowcs \- convert a multibyte string to a wide-character string |
3ea71b81 AC |
13 | .SH LIBRARY |
14 | Standard 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 |
26 | Feature 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 |
38 | The |
39 | .BR mbsnrtowcs () | |
40 | function is like the | |
3a72373c | 41 | .BR mbsrtowcs (3) |
60a90ecd | 42 | function, except that |
40aa0db0 MK |
43 | the number of bytes to be converted, starting at |
44 | .IR *src , | |
9caecea1 | 45 | is limited to at most |
1ae6b2c7 | 46 | .I nms |
9caecea1 | 47 | bytes. |
fea681da | 48 | .PP |
40aa0db0 MK |
49 | If |
50 | .I dest | |
b437fdd9 | 51 | is not NULL, the |
60a90ecd MK |
52 | .BR mbsnrtowcs () |
53 | function converts at | |
40aa0db0 MK |
54 | most |
55 | .I nms | |
56 | bytes from the | |
57 | multibyte string | |
58 | .I *src | |
59 | to a wide-character string starting at | |
60 | .IR dest . | |
61 | At most | |
62 | .I len | |
63 | wide characters are written to | |
64 | .IR dest . | |
c13182ef | 65 | The shift state |
40aa0db0 MK |
66 | .I *ps |
67 | is updated. | |
c13182ef | 68 | The conversion is effectively performed by repeatedly |
657e762d | 69 | calling |
0daa9e92 | 70 | .I "mbrtowc(dest, *src, n, ps)" |
40aa0db0 MK |
71 | where |
72 | .I n | |
73 | is some | |
fea681da | 74 | positive number, as long as this call succeeds, and then incrementing |
40aa0db0 MK |
75 | .I dest |
76 | by one and | |
77 | .I *src | |
78 | by the number of bytes consumed. | |
c13182ef | 79 | The |
fea681da | 80 | conversion can stop for three reasons: |
bce5f0ae | 81 | .IP 1. 3 |
bd0914f3 | 82 | An invalid multibyte sequence has been encountered. |
a8204fda | 83 | In this case, |
40aa0db0 | 84 | .I *src |
7d2cb9d5 | 85 | is left pointing to the invalid multibyte sequence, |
009df872 | 86 | .I (size_t)\ \-1 |
7d2cb9d5 | 87 | is returned, |
40aa0db0 MK |
88 | and |
89 | .I errno | |
90 | is set to | |
91 | .BR EILSEQ . | |
bce5f0ae | 92 | .IP 2. |
40aa0db0 MK |
93 | The |
94 | .I nms | |
95 | limit forces a stop, | |
96 | or | |
97 | .I len | |
d1a71985 | 98 | non-L\(aq\e0\(aq wide characters |
40aa0db0 MK |
99 | have been stored at |
100 | .IR dest . | |
a8204fda | 101 | In this case, |
40aa0db0 MK |
102 | .I *src |
103 | is left pointing to the | |
fea681da | 104 | next multibyte sequence to be converted, and the number of wide characters |
40aa0db0 MK |
105 | written to |
106 | .I dest | |
107 | is returned. | |
bce5f0ae MK |
108 | .IP 3. |
109 | The multibyte string has been completely converted, including the | |
d1a71985 | 110 | terminating null wide character (\(aq\e0\(aq) |
40aa0db0 MK |
111 | (which has the side effect of bringing back |
112 | .I *ps | |
113 | to the | |
c13182ef | 114 | initial state). |
a8204fda | 115 | In this case, |
40aa0db0 MK |
116 | .I *src |
117 | is set to NULL, and the number of wide | |
118 | characters written to | |
119 | .IR dest , | |
e9c23bc6 | 120 | excluding the terminating null wide character, |
fea681da MK |
121 | is returned. |
122 | .PP | |
5b711f5e MK |
123 | According to POSIX.1, |
124 | if the input buffer ends with an incomplete character, | |
125 | it is unspecified whether conversion stops at the end of | |
126 | the previous character (if any), or at the end of the input buffer. | |
127 | The glibc implementation adopts the former behavior. | |
847e0d88 | 128 | .PP |
40aa0db0 | 129 | If |
1ae6b2c7 | 130 | .I dest |
40aa0db0 MK |
131 | is NULL, |
132 | .I len | |
133 | is ignored, and the conversion proceeds as | |
fbe183be MK |
134 | above, except that the converted wide characters |
135 | are not written out to memory, | |
fea681da MK |
136 | and that no destination length limit exists. |
137 | .PP | |
40aa0db0 MK |
138 | In both of the above cases, if |
139 | .I ps | |
b437fdd9 | 140 | is NULL, a static anonymous |
7b3a353f MK |
141 | state known only to the |
142 | .BR mbsnrtowcs () | |
143 | function is used instead. | |
fea681da | 144 | .PP |
40aa0db0 MK |
145 | The programmer must ensure that there is room for at least |
146 | .I len | |
147 | wide | |
148 | characters at | |
149 | .IR dest . | |
47297adb | 150 | .SH RETURN VALUE |
60a90ecd MK |
151 | The |
152 | .BR mbsnrtowcs () | |
153 | function returns the number of wide characters | |
d0f17b57 | 154 | that make up the converted part of the wide-character string, |
fbe183be | 155 | not including the terminating null wide character. |
c13182ef | 156 | If an invalid multibyte sequence was |
7d2cb9d5 | 157 | encountered, |
009df872 | 158 | .I (size_t)\ \-1 |
40aa0db0 MK |
159 | is returned, and |
160 | .I errno | |
161 | set to | |
162 | .BR EILSEQ . | |
adad095f ZL |
163 | .SH ATTRIBUTES |
164 | For 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 |
169 | allbox; | |
b32feea5 | 170 | lb lb lbx |
adad095f ZL |
171 | l l l. |
172 | Interface Attribute Value | |
173 | T{ | |
174 | .BR mbsnrtowcs () | |
b32feea5 MK |
175 | T} Thread safety T{ |
176 | MT-Unsafe race:mbsnrtowcs/!ps | |
177 | T} | |
adad095f | 178 | .TE |
c466875e MK |
179 | .hy |
180 | .ad | |
847e0d88 | 181 | .sp 1 |
47297adb | 182 | .SH CONFORMING TO |
d9a8bda4 | 183 | POSIX.1-2008. |
fea681da | 184 | .SH NOTES |
d9bfdb9c | 185 | The behavior of |
60a90ecd | 186 | .BR mbsnrtowcs () |
1274071a MK |
187 | depends on the |
188 | .B LC_CTYPE | |
189 | category of the | |
fea681da MK |
190 | current locale. |
191 | .PP | |
40aa0db0 MK |
192 | Passing NULL as |
193 | .I ps | |
194 | is 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) |