]>
Commit | Line | Data |
---|---|---|
a1eaacb1 | 1 | '\" t |
fea681da MK |
2 | .\" Copyright (c) Bruno Haible <haible@clisp.cons.org> |
3 | .\" | |
e4a74ca8 | 4 | .\" SPDX-License-Identifier: GPL-2.0-or-later |
fea681da MK |
5 | .\" |
6 | .\" References consulted: | |
7 | .\" GNU glibc-2 source code and manual | |
8 | .\" Dinkumware C library reference http://www.dinkumware.com/ | |
008f1ecc | 9 | .\" OpenGroup's Single UNIX specification http://www.UNIX-systems.org/online.html |
fea681da MK |
10 | .\" ISO/IEC 9899:1999 |
11 | .\" | |
4c1c5274 | 12 | .TH mbsrtowcs 3 (date) "Linux man-pages (unreleased)" |
fea681da | 13 | .SH NAME |
d0f17b57 | 14 | mbsrtowcs \- convert a multibyte string to a wide-character string |
14cd5e25 AC |
15 | .SH LIBRARY |
16 | Standard C library | |
8fc3b2cf | 17 | .RI ( libc ", " \-lc ) |
fea681da MK |
18 | .SH SYNOPSIS |
19 | .nf | |
20 | .B #include <wchar.h> | |
68e4db0a | 21 | .PP |
1eed67e7 | 22 | .BI "size_t mbsrtowcs(wchar_t " dest "[restrict ." len "], const char **restrict " src , |
b4a5b818 | 23 | .BI " size_t " len ", mbstate_t *restrict " ps ); |
fea681da MK |
24 | .fi |
25 | .SH DESCRIPTION | |
40aa0db0 MK |
26 | If |
27 | .I dest | |
b437fdd9 | 28 | is not NULL, the |
60a90ecd MK |
29 | .BR mbsrtowcs () |
30 | function converts the | |
40aa0db0 MK |
31 | multibyte string |
32 | .I *src | |
33 | to a wide-character string starting at | |
34 | .IR dest . | |
35 | At most | |
36 | .I len | |
37 | wide characters are written to | |
38 | .IR dest . | |
c13182ef | 39 | The shift state |
40aa0db0 MK |
40 | .I *ps |
41 | is updated. | |
c13182ef | 42 | The conversion is effectively performed by repeatedly |
657e762d | 43 | calling |
0daa9e92 | 44 | .I "mbrtowc(dest, *src, n, ps)" |
40aa0db0 MK |
45 | where |
46 | .I n | |
47 | is some | |
fea681da | 48 | positive number, as long as this call succeeds, and then incrementing |
40aa0db0 MK |
49 | .I dest |
50 | by one and | |
51 | .I *src | |
52 | by the number of bytes consumed. | |
c13182ef | 53 | The conversion can stop for three reasons: |
cdede5cd | 54 | .IP \[bu] 3 |
bce5f0ae | 55 | An invalid multibyte sequence has been encountered. |
d99f93e8 | 56 | In this case, |
40aa0db0 | 57 | .I *src |
7d2cb9d5 | 58 | is left pointing to the invalid multibyte sequence, |
009df872 | 59 | .I (size_t)\ \-1 |
7d2cb9d5 | 60 | is returned, |
40aa0db0 MK |
61 | and |
62 | .I errno | |
63 | is set to | |
64 | .BR EILSEQ . | |
cdede5cd | 65 | .IP \[bu] |
40aa0db0 | 66 | .I len |
b957f81f | 67 | non-L\[aq]\e0\[aq] wide characters have been stored at |
40aa0db0 | 68 | .IR dest . |
d7e98586 | 69 | In this case, |
40aa0db0 MK |
70 | .I *src |
71 | is left pointing to the next | |
d9a10d9d | 72 | multibyte sequence to be converted, |
40aa0db0 MK |
73 | and the number of wide characters written to |
74 | .I dest | |
75 | is returned. | |
cdede5cd | 76 | .IP \[bu] |
bce5f0ae | 77 | The multibyte string has been completely converted, including the |
b957f81f | 78 | terminating null wide character (\[aq]\e0\[aq]), which has the side |
40aa0db0 MK |
79 | effect of bringing back |
80 | .I *ps | |
81 | to the | |
e9c23bc6 | 82 | initial state. |
d99f93e8 | 83 | In this case, |
40aa0db0 MK |
84 | .I *src |
85 | is set to NULL, and the number of wide | |
86 | characters written to | |
87 | .IR dest , | |
e9c23bc6 | 88 | excluding the terminating null wide character, is returned. |
fea681da | 89 | .PP |
40aa0db0 | 90 | If |
1ae6b2c7 | 91 | .I dest |
40aa0db0 MK |
92 | is NULL, |
93 | .I len | |
94 | is ignored, | |
d9a10d9d MK |
95 | and the conversion proceeds as above, |
96 | except that the converted wide characters are not written out to memory, | |
fea681da MK |
97 | and that no length limit exists. |
98 | .PP | |
d9a10d9d | 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 |
d9a10d9d MK |
104 | .BR mbsrtowcs () |
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 | wide | |
110 | characters at | |
111 | .IR dest . | |
47297adb | 112 | .SH RETURN VALUE |
60a90ecd MK |
113 | The |
114 | .BR mbsrtowcs () | |
115 | function returns the number of wide characters that make | |
d0f17b57 | 116 | up the converted part of the wide-character string, not including the |
c13182ef MK |
117 | terminating null wide character. |
118 | If an invalid multibyte sequence was | |
7d2cb9d5 | 119 | encountered, |
009df872 | 120 | .I (size_t)\ \-1 |
40aa0db0 MK |
121 | is returned, and |
122 | .I errno | |
123 | set to | |
124 | .BR EILSEQ . | |
03c07cb1 ZL |
125 | .SH ATTRIBUTES |
126 | For an explanation of the terms used in this section, see | |
127 | .BR attributes (7). | |
128 | .TS | |
129 | allbox; | |
b32feea5 | 130 | lb lb lbx |
03c07cb1 ZL |
131 | l l l. |
132 | Interface Attribute Value | |
133 | T{ | |
9e54434e BR |
134 | .na |
135 | .nh | |
03c07cb1 | 136 | .BR mbsrtowcs () |
b32feea5 | 137 | T} Thread safety T{ |
9e54434e BR |
138 | .na |
139 | .nh | |
b32feea5 MK |
140 | MT-Unsafe race:mbsrtowcs/!ps |
141 | T} | |
03c07cb1 | 142 | .TE |
847e0d88 | 143 | .sp 1 |
3113c7f3 | 144 | .SH STANDARDS |
4131356c AC |
145 | C11, POSIX.1-2008. |
146 | .SH HISTORY | |
147 | POSIX.1-2001, C99. | |
fea681da | 148 | .SH NOTES |
d9bfdb9c | 149 | The behavior of |
60a90ecd | 150 | .BR mbsrtowcs () |
1274071a MK |
151 | depends on the |
152 | .B LC_CTYPE | |
153 | category of the | |
fea681da MK |
154 | current locale. |
155 | .PP | |
40aa0db0 MK |
156 | Passing NULL as |
157 | .I ps | |
158 | is not multithread safe. | |
47297adb | 159 | .SH SEE ALSO |
e37e3282 | 160 | .BR iconv (3), |
9247e95b | 161 | .BR mbrtowc (3), |
65789f05 | 162 | .BR mbsinit (3), |
e37e3282 MK |
163 | .BR mbsnrtowcs (3), |
164 | .BR mbstowcs (3) |