]>
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 | .\" | |
1d767b55 | 11 | .TH MBSRTOWCS 3 2021-03-22 "GNU" "Linux Programmer's Manual" |
fea681da | 12 | .SH NAME |
d0f17b57 | 13 | mbsrtowcs \- convert a multibyte string to a wide-character string |
14cd5e25 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 |
b4a5b818 AC |
21 | .BI "size_t mbsrtowcs(wchar_t *restrict " dest ", const char **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, the |
60a90ecd MK |
28 | .BR mbsrtowcs () |
29 | function converts the | |
40aa0db0 MK |
30 | multibyte string |
31 | .I *src | |
32 | to a wide-character string starting at | |
33 | .IR dest . | |
34 | At most | |
35 | .I len | |
36 | wide characters are written to | |
37 | .IR dest . | |
c13182ef | 38 | The shift state |
40aa0db0 MK |
39 | .I *ps |
40 | is updated. | |
c13182ef | 41 | The conversion is effectively performed by repeatedly |
657e762d | 42 | calling |
0daa9e92 | 43 | .I "mbrtowc(dest, *src, n, ps)" |
40aa0db0 MK |
44 | where |
45 | .I n | |
46 | is some | |
fea681da | 47 | positive number, as long as this call succeeds, and then incrementing |
40aa0db0 MK |
48 | .I dest |
49 | by one and | |
50 | .I *src | |
51 | by the number of bytes consumed. | |
c13182ef | 52 | The conversion can stop for three reasons: |
bce5f0ae MK |
53 | .IP 1. 3 |
54 | An invalid multibyte sequence has been encountered. | |
d99f93e8 | 55 | In this case, |
40aa0db0 | 56 | .I *src |
7d2cb9d5 | 57 | is left pointing to the invalid multibyte sequence, |
009df872 | 58 | .I (size_t)\ \-1 |
7d2cb9d5 | 59 | is returned, |
40aa0db0 MK |
60 | and |
61 | .I errno | |
62 | is set to | |
63 | .BR EILSEQ . | |
bce5f0ae | 64 | .IP 2. |
40aa0db0 | 65 | .I len |
d1a71985 | 66 | non-L\(aq\e0\(aq wide characters have been stored at |
40aa0db0 | 67 | .IR dest . |
d7e98586 | 68 | In this case, |
40aa0db0 MK |
69 | .I *src |
70 | is left pointing to the next | |
d9a10d9d | 71 | multibyte sequence to be converted, |
40aa0db0 MK |
72 | and the number of wide characters written to |
73 | .I dest | |
74 | is returned. | |
bce5f0ae MK |
75 | .IP 3. |
76 | The multibyte string has been completely converted, including the | |
d1a71985 | 77 | terminating null wide character (\(aq\e0\(aq), which has the side |
40aa0db0 MK |
78 | effect of bringing back |
79 | .I *ps | |
80 | to the | |
e9c23bc6 | 81 | initial state. |
d99f93e8 | 82 | In this case, |
40aa0db0 MK |
83 | .I *src |
84 | is set to NULL, and the number of wide | |
85 | characters written to | |
86 | .IR dest , | |
e9c23bc6 | 87 | excluding the terminating null wide character, is returned. |
fea681da | 88 | .PP |
40aa0db0 | 89 | If |
1ae6b2c7 | 90 | .I dest |
40aa0db0 MK |
91 | is NULL, |
92 | .I len | |
93 | is ignored, | |
d9a10d9d MK |
94 | and the conversion proceeds as above, |
95 | except that the converted wide characters are not written out to memory, | |
fea681da MK |
96 | and that no length limit exists. |
97 | .PP | |
d9a10d9d | 98 | In both of the above cases, |
40aa0db0 MK |
99 | if |
100 | .I ps | |
b437fdd9 | 101 | is NULL, a static anonymous |
33a0ccb2 | 102 | state known only to the |
d9a10d9d MK |
103 | .BR mbsrtowcs () |
104 | function is used instead. | |
fea681da | 105 | .PP |
40aa0db0 MK |
106 | The programmer must ensure that there is room for at least |
107 | .I len | |
108 | wide | |
109 | characters at | |
110 | .IR dest . | |
47297adb | 111 | .SH RETURN VALUE |
60a90ecd MK |
112 | The |
113 | .BR mbsrtowcs () | |
114 | function returns the number of wide characters that make | |
d0f17b57 | 115 | up the converted part of the wide-character string, not including the |
c13182ef MK |
116 | terminating null wide character. |
117 | If an invalid multibyte sequence was | |
7d2cb9d5 | 118 | encountered, |
009df872 | 119 | .I (size_t)\ \-1 |
40aa0db0 MK |
120 | is returned, and |
121 | .I errno | |
122 | set to | |
123 | .BR EILSEQ . | |
03c07cb1 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 | |
03c07cb1 ZL |
129 | .TS |
130 | allbox; | |
b32feea5 | 131 | lb lb lbx |
03c07cb1 ZL |
132 | l l l. |
133 | Interface Attribute Value | |
134 | T{ | |
135 | .BR mbsrtowcs () | |
b32feea5 MK |
136 | T} Thread safety T{ |
137 | MT-Unsafe race:mbsrtowcs/!ps | |
138 | T} | |
03c07cb1 | 139 | .TE |
c466875e MK |
140 | .hy |
141 | .ad | |
847e0d88 | 142 | .sp 1 |
47297adb | 143 | .SH CONFORMING TO |
765c9ca2 | 144 | POSIX.1-2001, POSIX.1-2008, C99. |
fea681da | 145 | .SH NOTES |
d9bfdb9c | 146 | The behavior of |
60a90ecd | 147 | .BR mbsrtowcs () |
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), |
9247e95b | 158 | .BR mbrtowc (3), |
65789f05 | 159 | .BR mbsinit (3), |
e37e3282 MK |
160 | .BR mbsnrtowcs (3), |
161 | .BR mbstowcs (3) |