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