]>
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 | .\" |
4c1c5274 | 10 | .TH wcsnrtombs 3 (date) "Linux man-pages (unreleased)" |
fea681da | 11 | .SH NAME |
d0f17b57 | 12 | wcsnrtombs \- convert a wide-character string to a multibyte string |
9593c48f 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 |
c37f316d AC |
20 | .BI "size_t wcsnrtombs(char *restrict " dest ", const wchar_t **restrict " src , |
21 | .BI " size_t " nwc ", 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 wcsnrtombs (): |
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 wcsnrtombs () | |
40 | function is like the | |
9daa4fb9 | 41 | .BR wcsrtombs (3) |
60a90ecd | 42 | function, |
c13182ef | 43 | except that the number of wide characters to be converted, |
40aa0db0 MK |
44 | starting at |
45 | .IR *src , | |
46 | is limited to | |
47 | .IR nwc . | |
fea681da | 48 | .PP |
40aa0db0 MK |
49 | If |
50 | .I dest | |
b437fdd9 | 51 | is not NULL, |
60a90ecd MK |
52 | the |
53 | .BR wcsnrtombs () | |
54 | function converts | |
40aa0db0 MK |
55 | at most |
56 | .I nwc | |
57 | wide characters from | |
58 | the wide-character string | |
59 | .I *src | |
60 | to a multibyte string starting at | |
61 | .IR dest . | |
62 | At most | |
63 | .I len | |
64 | bytes are written to | |
65 | .IR dest . | |
c13182ef | 66 | The shift state |
40aa0db0 MK |
67 | .I *ps |
68 | is updated. | |
c13182ef | 69 | The conversion is effectively performed by repeatedly |
657e762d | 70 | calling |
930d718c | 71 | .IR "wcrtomb(dest, *src, ps)" , |
c13182ef | 72 | as long as this call succeeds, |
40aa0db0 MK |
73 | and then incrementing |
74 | .I dest | |
75 | by the | |
76 | number of bytes written and | |
77 | .I *src | |
c13182ef MK |
78 | by one. |
79 | The conversion can stop for three reasons: | |
22356d97 | 80 | .IP \(bu 3 |
7fc50d4a | 81 | A wide character has been encountered that can not be represented as a |
c13182ef | 82 | multibyte sequence (according to the current locale). |
d38ff9af | 83 | In this case, |
40aa0db0 | 84 | .I *src |
7d2cb9d5 | 85 | is left pointing to the invalid wide character, |
009df872 | 86 | .I (size_t)\ \-1 |
7d2cb9d5 | 87 | is returned, |
40aa0db0 MK |
88 | and |
89 | .I errno | |
90 | is set to | |
91 | .BR EILSEQ . | |
22356d97 | 92 | .IP \(bu |
40aa0db0 MK |
93 | .I nwc |
94 | wide characters have been | |
d1a71985 | 95 | converted without encountering a null wide character (L\(aq\e0\(aq), |
c13182ef | 96 | or the length limit forces a stop. |
d38ff9af | 97 | In this case, |
40aa0db0 MK |
98 | .I *src |
99 | is left pointing | |
fea681da | 100 | to the next wide character to be converted, and the number of bytes written |
40aa0db0 MK |
101 | to |
102 | .I dest | |
103 | is returned. | |
22356d97 | 104 | .IP \(bu |
7fc50d4a | 105 | The wide-character string has been completely converted, including the |
40aa0db0 MK |
106 | terminating null wide character (which has the side effect of bringing back |
107 | .I *ps | |
c13182ef | 108 | to the initial state). |
d38ff9af | 109 | In this case, |
40aa0db0 MK |
110 | .I *src |
111 | is set to NULL, and the number | |
112 | of bytes written to | |
113 | .IR dest , | |
d1a71985 | 114 | excluding the terminating null byte (\(aq\e0\(aq), is |
fea681da MK |
115 | returned. |
116 | .PP | |
40aa0db0 | 117 | If |
1ae6b2c7 | 118 | .I dest |
40aa0db0 MK |
119 | is NULL, |
120 | .I len | |
121 | is ignored, | |
c13182ef MK |
122 | and the conversion proceeds as above, |
123 | except that the converted bytes are not written out to memory, and that | |
fea681da MK |
124 | no destination length limit exists. |
125 | .PP | |
c13182ef | 126 | In both of the above cases, |
40aa0db0 MK |
127 | if |
128 | .I ps | |
b437fdd9 | 129 | is NULL, a static anonymous |
33a0ccb2 | 130 | state known only to the |
1c008960 MK |
131 | .BR wcsnrtombs () |
132 | function is used instead. | |
fea681da | 133 | .PP |
40aa0db0 MK |
134 | The programmer must ensure that there is room for at least |
135 | .I len | |
136 | bytes | |
137 | at | |
138 | .IR dest . | |
47297adb | 139 | .SH RETURN VALUE |
60a90ecd MK |
140 | The |
141 | .BR wcsnrtombs () | |
142 | function returns | |
c13182ef MK |
143 | the number of bytes that make up the |
144 | converted part of multibyte sequence, | |
3c81e148 | 145 | not including the terminating null byte. |
c13182ef | 146 | If a wide character was encountered which |
7d2cb9d5 | 147 | could not be converted, |
009df872 | 148 | .I (size_t)\ \-1 |
40aa0db0 MK |
149 | is returned, and |
150 | .I errno | |
151 | set to | |
152 | .BR EILSEQ . | |
6d4209de ZL |
153 | .SH ATTRIBUTES |
154 | For an explanation of the terms used in this section, see | |
155 | .BR attributes (7). | |
c466875e MK |
156 | .ad l |
157 | .nh | |
6d4209de ZL |
158 | .TS |
159 | allbox; | |
b32feea5 | 160 | lb lb lbx |
6d4209de ZL |
161 | l l l. |
162 | Interface Attribute Value | |
163 | T{ | |
164 | .BR wcsnrtombs () | |
b32feea5 MK |
165 | T} Thread safety T{ |
166 | MT-Unsafe race:wcsnrtombs/!ps | |
167 | T} | |
6d4209de | 168 | .TE |
c466875e MK |
169 | .hy |
170 | .ad | |
847e0d88 | 171 | .sp 1 |
3113c7f3 | 172 | .SH STANDARDS |
d9a8bda4 | 173 | POSIX.1-2008. |
fea681da | 174 | .SH NOTES |
d9bfdb9c | 175 | The behavior of |
60a90ecd | 176 | .BR wcsnrtombs () |
1274071a MK |
177 | depends on the |
178 | .B LC_CTYPE | |
179 | category of the | |
fea681da MK |
180 | current locale. |
181 | .PP | |
40aa0db0 MK |
182 | Passing NULL as |
183 | .I ps | |
184 | is not multithread safe. | |
47297adb | 185 | .SH SEE ALSO |
e37e3282 | 186 | .BR iconv (3), |
4670051b | 187 | .BR mbsinit (3), |
e37e3282 | 188 | .BR wcsrtombs (3) |