OSDN Git Service

LDP: Update original to LDP v3.79
[linuxjm/LDP_man-pages.git] / original / man3 / wcstombs.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 WCSTOMBS 3  2014-03-18 "GNU" "Linux Programmer's Manual"
17 .SH NAME
18 wcstombs \- convert a wide-character string to a multibyte string
19 .SH SYNOPSIS
20 .nf
21 .B #include <stdlib.h>
22 .sp
23 .BI "size_t wcstombs(char *" dest ", const wchar_t *" src ", size_t " n );
24 .fi
25 .SH DESCRIPTION
26 If
27 .I dest
28 is not NULL, the
29 .BR wcstombs ()
30 function converts
31 the wide-character string
32 .I src
33 to a multibyte string starting at
34 .IR dest .
35 At most
36 .I n
37 bytes are written to
38 .IR dest .
39 The conversion
40 starts in the initial state.
41 The conversion can stop for three reasons:
42 .PP
43 1. A wide character has been encountered that can not be represented as a
44 multibyte sequence (according to the current locale).
45 In this case,
46 .I (size_t)\ \-1
47 is returned.
48 .PP
49 2. The length limit forces a stop.
50 In this case, the number of bytes written to
51 .I dest
52 is returned, but the shift state at this point is lost.
53 .PP
54 3. The wide-character string has been completely converted, including the
55 terminating null wide character (L\(aq\\0\(aq).
56 In this case, the conversion ends in the initial state.
57 The number of bytes written to
58 .IR dest ,
59 excluding the terminating null byte (\(aq\\0\(aq), is returned.
60 .PP
61 The programmer must ensure that there is room for at least
62 .I n
63 bytes
64 at
65 .IR dest .
66 .PP
67 If
68 .IR dest
69 is NULL,
70 .I n
71 is ignored, and the conversion proceeds as
72 above, except that the converted bytes are not written out to memory,
73 and no length limit exists.
74 .PP
75 In order to avoid the case 2 above, the programmer should make sure
76 .I n
77 is greater than or equal to
78 .IR "wcstombs(NULL,src,0)+1" .
79 .SH RETURN VALUE
80 The
81 .BR wcstombs ()
82 function returns the number of bytes that make up the
83 converted part of a multibyte sequence,
84 not including the terminating null byte.
85 If a wide character was encountered which could not be
86 converted,
87 .I (size_t)\ \-1
88 is returned.
89 .SH CONFORMING TO
90 C99.
91 .SH NOTES
92 The behavior of
93 .BR wcstombs ()
94 depends on the
95 .B LC_CTYPE
96 category of the
97 current locale.
98 .PP
99 The function
100 .BR wcsrtombs (3)
101 provides a thread safe interface to
102 the same functionality.
103 .SH SEE ALSO
104 .BR mblen (3),
105 .BR mbtowc (3),
106 .BR mbstowcs (3),
107 .BR wcsrtombs (3)
108 .BR wctom (3)
109 .SH COLOPHON
110 This page is part of release 3.79 of the Linux
111 .I man-pages
112 project.
113 A description of the project,
114 information about reporting bugs,
115 and the latest version of this page,
116 can be found at
117 \%http://www.kernel.org/doc/man\-pages/.