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