]>
Commit | Line | Data |
---|---|---|
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 | 14 | .\" |
4b8c67d9 | 15 | .TH WCSNRTOMBS 3 2017-09-15 "GNU" "Linux Programmer's Manual" |
fea681da | 16 | .SH NAME |
d0f17b57 | 17 | wcsnrtombs \- convert a wide-character string to a multibyte string |
fea681da MK |
18 | .SH SYNOPSIS |
19 | .nf | |
20 | .B #include <wchar.h> | |
68e4db0a | 21 | .PP |
fea681da | 22 | .BI "size_t wcsnrtombs(char *" dest ", const wchar_t **" src ", size_t " nwc , |
b9f02710 | 23 | .BI " size_t " len ", mbstate_t *" ps ); |
fea681da | 24 | .fi |
68e4db0a | 25 | .PP |
7dbff9b4 MK |
26 | .in -4n |
27 | Feature Test Macro Requirements for glibc (see | |
28 | .BR feature_test_macros (7)): | |
29 | .in | |
68e4db0a | 30 | .PP |
7dbff9b4 | 31 | .BR wcsnrtombs (): |
ea91c3fd MK |
32 | .PD 0 |
33 | .ad l | |
34 | .RS 4 | |
35 | .TP 4 | |
36 | Since glibc 2.10: | |
b0da7b8b | 37 | _POSIX_C_SOURCE\ >=\ 200809L |
ea91c3fd | 38 | .TP |
7dbff9b4 MK |
39 | Before glibc 2.10: |
40 | _GNU_SOURCE | |
ea91c3fd MK |
41 | .RE |
42 | .ad | |
43 | .PD | |
fea681da | 44 | .SH DESCRIPTION |
60a90ecd MK |
45 | The |
46 | .BR wcsnrtombs () | |
47 | function is like the | |
9daa4fb9 | 48 | .BR wcsrtombs (3) |
60a90ecd | 49 | function, |
c13182ef | 50 | except that the number of wide characters to be converted, |
40aa0db0 MK |
51 | starting at |
52 | .IR *src , | |
53 | is limited to | |
54 | .IR nwc . | |
fea681da | 55 | .PP |
40aa0db0 MK |
56 | If |
57 | .I dest | |
b437fdd9 | 58 | is not NULL, |
60a90ecd MK |
59 | the |
60 | .BR wcsnrtombs () | |
61 | function converts | |
40aa0db0 MK |
62 | at most |
63 | .I nwc | |
64 | wide characters from | |
65 | the wide-character string | |
66 | .I *src | |
67 | to a multibyte string starting at | |
68 | .IR dest . | |
69 | At most | |
70 | .I len | |
71 | bytes are written to | |
72 | .IR dest . | |
c13182ef | 73 | The shift state |
40aa0db0 MK |
74 | .I *ps |
75 | is updated. | |
c13182ef | 76 | The conversion is effectively performed by repeatedly |
657e762d | 77 | calling |
930d718c | 78 | .IR "wcrtomb(dest, *src, ps)" , |
c13182ef | 79 | as long as this call succeeds, |
40aa0db0 MK |
80 | and then incrementing |
81 | .I dest | |
82 | by the | |
83 | number of bytes written and | |
84 | .I *src | |
c13182ef MK |
85 | by one. |
86 | The conversion can stop for three reasons: | |
7fc50d4a MK |
87 | .IP 1. 3 |
88 | A wide character has been encountered that can not be represented as a | |
c13182ef | 89 | multibyte sequence (according to the current locale). |
d38ff9af | 90 | In this case, |
40aa0db0 | 91 | .I *src |
7d2cb9d5 | 92 | is left pointing to the invalid wide character, |
009df872 | 93 | .I (size_t)\ \-1 |
7d2cb9d5 | 94 | is returned, |
40aa0db0 MK |
95 | and |
96 | .I errno | |
97 | is set to | |
98 | .BR EILSEQ . | |
7fc50d4a | 99 | .IP 2. |
40aa0db0 MK |
100 | .I nwc |
101 | wide characters have been | |
e9c23bc6 | 102 | converted without encountering a null wide character (L\(aq\\0\(aq), |
c13182ef | 103 | or the length limit forces a stop. |
d38ff9af | 104 | In this case, |
40aa0db0 MK |
105 | .I *src |
106 | is left pointing | |
fea681da | 107 | to the next wide character to be converted, and the number of bytes written |
40aa0db0 MK |
108 | to |
109 | .I dest | |
110 | is returned. | |
7fc50d4a MK |
111 | .IP 3. |
112 | The wide-character string has been completely converted, including the | |
40aa0db0 MK |
113 | terminating null wide character (which has the side effect of bringing back |
114 | .I *ps | |
c13182ef | 115 | to the initial state). |
d38ff9af | 116 | In this case, |
40aa0db0 MK |
117 | .I *src |
118 | is set to NULL, and the number | |
119 | of bytes written to | |
120 | .IR dest , | |
3c81e148 | 121 | excluding the terminating null byte (\(aq\\0\(aq), is |
fea681da MK |
122 | returned. |
123 | .PP | |
40aa0db0 | 124 | If |
51700fd7 | 125 | .IR dest |
40aa0db0 MK |
126 | is NULL, |
127 | .I len | |
128 | is ignored, | |
c13182ef MK |
129 | and the conversion proceeds as above, |
130 | except that the converted bytes are not written out to memory, and that | |
fea681da MK |
131 | no destination length limit exists. |
132 | .PP | |
c13182ef | 133 | In both of the above cases, |
40aa0db0 MK |
134 | if |
135 | .I ps | |
b437fdd9 | 136 | is NULL, a static anonymous |
33a0ccb2 | 137 | state known only to the |
1c008960 MK |
138 | .BR wcsnrtombs () |
139 | function is used instead. | |
fea681da | 140 | .PP |
40aa0db0 MK |
141 | The programmer must ensure that there is room for at least |
142 | .I len | |
143 | bytes | |
144 | at | |
145 | .IR dest . | |
47297adb | 146 | .SH RETURN VALUE |
60a90ecd MK |
147 | The |
148 | .BR wcsnrtombs () | |
149 | function returns | |
c13182ef MK |
150 | the number of bytes that make up the |
151 | converted part of multibyte sequence, | |
3c81e148 | 152 | not including the terminating null byte. |
c13182ef | 153 | If a wide character was encountered which |
7d2cb9d5 | 154 | could not be converted, |
009df872 | 155 | .I (size_t)\ \-1 |
40aa0db0 MK |
156 | is returned, and |
157 | .I errno | |
158 | set to | |
159 | .BR EILSEQ . | |
6d4209de ZL |
160 | .SH ATTRIBUTES |
161 | For an explanation of the terms used in this section, see | |
162 | .BR attributes (7). | |
163 | .TS | |
164 | allbox; | |
165 | lb lb lbw29 | |
166 | l l l. | |
167 | Interface Attribute Value | |
168 | T{ | |
169 | .BR wcsnrtombs () | |
170 | T} Thread safety MT-Unsafe race:wcsnrtombs/!ps | |
171 | .TE | |
847e0d88 | 172 | .sp 1 |
47297adb | 173 | .SH CONFORMING TO |
d9a8bda4 | 174 | POSIX.1-2008. |
fea681da | 175 | .SH NOTES |
d9bfdb9c | 176 | The behavior of |
60a90ecd | 177 | .BR wcsnrtombs () |
1274071a MK |
178 | depends on the |
179 | .B LC_CTYPE | |
180 | category of the | |
fea681da MK |
181 | current locale. |
182 | .PP | |
40aa0db0 MK |
183 | Passing NULL as |
184 | .I ps | |
185 | is not multithread safe. | |
47297adb | 186 | .SH SEE ALSO |
e37e3282 | 187 | .BR iconv (3), |
4670051b | 188 | .BR mbsinit (3), |
e37e3282 | 189 | .BR wcsrtombs (3) |