2 .TH %PAGEREF% MinGW "MinGW Programmer's Reference Manual"
6 \- convert a wide character to a multibyte sequence
13 .B size_t wcsrtombs( char
27 function converts a sequence of wide characters from
28 the array which is indirectly pointed to by
30 to a corresponding multibyte character sequence in
31 the codeset which is associated with the
33 category of the active process locale,
34 beginning in the conversion state which is represented by the
38 each wide character is converted,
44 Conversion continues until:
48 A wide character which is invalid in its own context is encountered.
51 A wide character which does not have a valid representation within
52 the target multibyte codeset is encountered.
55 The NUL wide character is encountered,
56 while in the initial conversion state.
61 argument is not a NULL pointer,
62 and a wide character is encountered for which
63 the converted length would cause the aggregate length
64 of the converted multibyte character string to exceed
65 the limit specified by the
77 the multibyte character string resulting from successful conversion,
81 is stored in the multibyte array starting at
83 If the conversion is NUL terminated,
84 the wide character string reference pointed to by
86 is replaced by a NULL pointer;
87 otherwise it is updated to point to the address immediately
88 following that of the last wide character converted.
94 the aggregate count of bytes required
95 to represent the conversion is accumulated,
96 until any one of the preceding termination conditions is encountered;
100 and the termination condition which is dependent upon it,
102 and the conversion is not stored.
110 function uses a static internal
113 which is known only to,
114 and visible only within the scope of execution of,
120 Following a successful conversion,
127 object if appropriate,
128 is reset to the initial conversion state.
132 When conversion is successful,
140 function returns the number of bytes stored at
142 to represent the resulting multibyte character sequence,
149 when conversion is successful,
155 function returns the number of bytes which would be required
156 to store the entire multibyte character string resulting from
157 the successful conversion,
163 If conversion is unsuccessful,
171 and the conversion state is unspecified.
174 .SH STANDARDS CONFORMANCE
175 Except in respect of its extended provision for handling of
176 .IR surrogate\ pairs ,
177 and to the extent that it may be affected by limitations
178 of the underlying \%MS\(hyWindows API,
183 conforms generally to
185 .BR \%POSIX.1\(hy2001 ,
187 .BR \%POSIX.1\(hy2008 .
194 Due to a documented limitation of Microsoft\(aqs
196 function implementation,
197 it is not possible to directly select an active locale,
198 in which the codeset is represented by any multibyte
199 character sequence with an effective
201 of more than two bytes.
202 Prior to \%mingwrt\(hy5.3,
203 this limitation precludes the use of
205 to convert to any codeset with
207 greater than two bytes,
210 From \%mingwrt\(hy5.3 onward,
211 the MinGW.org implementation of
213 mitigates this limitation by assignment of the codeset
216 environment variable,
217 provided the system default has been previously activated
225 #define _ISOC99_SOURCE
232 void print_conv( const wchar_t * );
236 setlocale( LC_CTYPE, "" );
237 putenv( "LC_CTYPE=en_GB.65001" );
238 print_conv( L"\eu6c34\eU0001d10b" );
242 void print_conv( const wchar_t *wcs )
245 if( (len = 1 + wcsrtombs( NULL, &wcs, 0, NULL )) > 0 )
247 const wchar_t *wc = wcs;
248 size_t n = 1 + wcslen( wcs );
249 unsigned char mbs[len], *mb = mbs;
250 printf( "UTF-16: %u value%s: ", n, (n == 1) ? "" : "s" );
251 do { printf( "0x%04X%c", *wc, (*wc == L'\e0') ? '\en' : ':' );
252 } while( *p++ != L'\e0' );
253 printf( "UTF-8: %u byte%s: ",
254 1 + wcsrtombs( mbs, &wcs, len, NULL ),
255 (len == 1) ? "" : "s"
257 do { printf( "0x%02X%s", *mb, (*mb == '\e0') ? '\en' : ':' );
258 } while( *mb++ != '\e0' );
260 else perror( "wcsrtombs" );
267 as the target codeset,
268 then convert the \fC\%L"\eu6c34\eU0001d10b"\fP
269 wide character string,
270 resulting in the output:
274 UTF-16: 4 values: 0x6C34:0xD834:0xDD0B:0x0000
275 UTF-8: 8 bytes: 0xE6:0xB0:0xB4:0xF0:0x9D:0x84:0x8B:0x00
287 This manpage was written by \%Keith\ Marshall,
288 \%<keith@users.osdn.me>,
291 function as it has been implemented for the MinGW.org Project.
292 It may be copied, modified and redistributed,
293 without restriction of copyright,
294 provided this acknowledgement of contribution by
295 the original author remains in place.