OSDN Git Service

(split) LDP: Update original to LDP v3.51.
[linuxjm/LDP_man-pages.git] / original / man3 / wcsnrtombs.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 .\"
15 .TH WCSNRTOMBS 3  2011-10-16 "GNU" "Linux Programmer's Manual"
16 .SH NAME
17 wcsnrtombs \- convert a wide-character string to a multibyte string
18 .SH SYNOPSIS
19 .nf
20 .B #include <wchar.h>
21 .sp
22 .BI "size_t wcsnrtombs(char *" dest ", const wchar_t **" src ", size_t " nwc ,
23 .BI "                  size_t " len ", mbstate_t *" ps );
24 .fi
25 .sp
26 .in -4n
27 Feature Test Macro Requirements for glibc (see
28 .BR feature_test_macros (7)):
29 .in
30 .sp
31 .BR wcsnrtombs ():
32 .PD 0
33 .ad l
34 .RS 4
35 .TP 4
36 Since glibc 2.10:
37 _XOPEN_SOURCE\ >=\ 700 || _POSIX_C_SOURCE\ >=\ 200809L
38 .TP
39 Before glibc 2.10:
40 _GNU_SOURCE
41 .RE
42 .ad
43 .PD
44 .SH DESCRIPTION
45 The
46 .BR wcsnrtombs ()
47 function is like the
48 .BR wcsrtombs (3)
49 function,
50 except that the number of wide characters to be converted,
51 starting at \fI*src\fP, is limited to \fInwc\fP.
52 .PP
53 If \fIdest\fP is not a NULL pointer,
54 the
55 .BR wcsnrtombs ()
56 function converts
57 at most \fInwc\fP wide characters from
58 the wide-character string \fI*src\fP to a multibyte string starting at
59 \fIdest\fP.
60 At most \fIlen\fP bytes are written to \fIdest\fP.
61 The shift state
62 \fI*ps\fP is updated.
63 The conversion is effectively performed by repeatedly
64 calling
65 .IR "wcrtomb(dest, *src, ps)" ,
66 as long as this call succeeds,
67 and then incrementing \fIdest\fP by the
68 number of bytes written and \fI*src\fP
69 by one.
70 The conversion can stop for three reasons:
71 .PP
72 1. A wide character has been encountered that can not be represented as a
73 multibyte sequence (according to the current locale).
74 In this case \fI*src\fP
75 is left pointing to the invalid wide character,
76 .I (size_t)\ \-1
77 is returned,
78 and \fIerrno\fP is set to \fBEILSEQ\fP.
79 .PP
80 2. \fInwc\fP wide characters have been
81 converted without encountering a null wide character (L\(aq\\0\(aq),
82 or the length limit forces a stop.
83 In this case \fI*src\fP is left pointing
84 to the next wide character to be converted, and the number of bytes written
85 to \fIdest\fP is returned.
86 .PP
87 3. The wide-character string has been completely converted, including the
88 terminating null wide character (which has the side effect of bringing back \fI*ps\fP
89 to the initial state).
90 In this case \fI*src\fP is set to NULL, and the number
91 of bytes written to \fIdest\fP,
92 excluding the terminating null byte (\(aq\\0\(aq), is
93 returned.
94 .PP
95 If \fIdest\fP is NULL, \fIlen\fP is ignored,
96 and the conversion proceeds as above,
97 except that the converted bytes are not written out to memory, and that
98 no destination length limit exists.
99 .PP
100 In both of the above cases,
101 if \fIps\fP is a NULL pointer, a static anonymous
102 state known only to the
103 .BR wcsnrtombs ()
104 function is used instead.
105 .PP
106 The programmer must ensure that there is room for at least \fIlen\fP bytes
107 at \fIdest\fP.
108 .SH RETURN VALUE
109 The
110 .BR wcsnrtombs ()
111 function returns
112 the number of bytes that make up the
113 converted part of multibyte sequence,
114 not including the terminating null byte.
115 If a wide character was encountered which
116 could not be converted,
117 .I (size_t)\ \-1
118 is returned, and \fIerrno\fP set to \fBEILSEQ\fP.
119 .SH CONFORMING TO
120 POSIX.1-2008.
121 .SH NOTES
122 The behavior of
123 .BR wcsnrtombs ()
124 depends on the
125 .B LC_CTYPE
126 category of the
127 current locale.
128 .PP
129 Passing NULL as \fIps\fP is not multithread safe.
130 .SH SEE ALSO
131 .BR iconv (3),
132 .BR wcsrtombs (3)