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