OSDN Git Service

(split) LDP: Update original to LDP v3.51.
[linuxjm/LDP_man-pages.git] / original / man3 / mbsrtowcs.3
1 .\" Copyright (c) Bruno Haible <haible@clisp.cons.org>
2 .\"
3 .\" %%%LICENSE_START(GPLv2+_DOC_ONEPARA)
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.
8 .\" %%%LICENSE_END
9 .\"
10 .\" References consulted:
11 .\"   GNU glibc-2 source code and manual
12 .\"   Dinkumware C library reference http://www.dinkumware.com/
13 .\"   OpenGroup's Single UNIX specification http://www.UNIX-systems.org/online.html
14 .\"   ISO/IEC 9899:1999
15 .\"
16 .TH MBSRTOWCS 3  2011-09-28 "GNU" "Linux Programmer's Manual"
17 .SH NAME
18 mbsrtowcs \- convert a multibyte string to a wide-character string
19 .SH SYNOPSIS
20 .nf
21 .B #include <wchar.h>
22 .sp
23 .BI "size_t mbsrtowcs(wchar_t *" dest ", const char **" src ,
24 .BI "                  size_t " len ", mbstate_t *" ps );
25 .fi
26 .SH DESCRIPTION
27 If \fIdest\fP is not a NULL pointer, the
28 .BR mbsrtowcs ()
29 function converts the
30 multibyte string \fI*src\fP to a wide-character string starting at \fIdest\fP.
31 At most \fIlen\fP wide characters are written to \fIdest\fP.
32 The shift state
33 \fI*ps\fP is updated.
34 The conversion is effectively performed by repeatedly
35 calling
36 .I "mbrtowc(dest, *src, n, ps)"
37 where \fIn\fP is some
38 positive number, as long as this call succeeds, and then incrementing
39 \fIdest\fP by one and \fI*src\fP by the number of bytes consumed.
40 The conversion can stop for three reasons:
41 .IP 1. 3
42 An invalid multibyte sequence has been encountered.
43 In this case \fI*src\fP
44 is left pointing to the invalid multibyte sequence,
45 .I (size_t)\ \-1
46 is returned,
47 and \fIerrno\fP is set to \fBEILSEQ\fP.
48 .IP 2.
49 \fIlen\fP non-L\(aq\\0\(aq wide characters have been stored at \fIdest\fP.
50 In this
51 case \fI*src\fP is left pointing to the next
52 multibyte sequence to be converted,
53 and the number of wide characters written to \fIdest\fP is returned.
54 .IP 3.
55 The multibyte string has been completely converted, including the
56 terminating null wide character (\(aq\\0\(aq), which has the side
57 effect of bringing back \fI*ps\fP to the
58 initial state.
59 In this case \fI*src\fP is set to NULL, and the number of wide
60 characters written to \fIdest\fP,
61 excluding the terminating null wide character, is returned.
62 .PP
63 If \fIdest\fP is NULL, \fIlen\fP is ignored,
64 and the conversion proceeds as above,
65 except that the converted wide characters are not written out to memory,
66 and that no length limit exists.
67 .PP
68 In both of the above cases,
69 if \fIps\fP is a NULL pointer, a static anonymous
70 state known only to the
71 .BR mbsrtowcs ()
72 function is used instead.
73 .PP
74 The programmer must ensure that there is room for at least \fIlen\fP wide
75 characters at \fIdest\fP.
76 .SH RETURN VALUE
77 The
78 .BR mbsrtowcs ()
79 function returns the number of wide characters that make
80 up the converted part of the wide-character string, not including the
81 terminating null wide character.
82 If an invalid multibyte sequence was
83 encountered,
84 .I (size_t)\ \-1
85 is returned, and \fIerrno\fP set to \fBEILSEQ\fP.
86 .SH CONFORMING TO
87 C99.
88 .SH NOTES
89 The behavior of
90 .BR mbsrtowcs ()
91 depends on the
92 .B LC_CTYPE
93 category of the
94 current locale.
95 .PP
96 Passing NULL as \fIps\fP is not multithread safe.
97 .SH SEE ALSO
98 .BR iconv (3),
99 .BR mbsnrtowcs (3),
100 .BR mbstowcs (3)