OSDN Git Service

1e1b045c6dc7f4e0b3aac4c26b99563daaf1d3c7
[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  2011-10-16 "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 a NULL pointer, 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 that 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 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 multibyte sequence, not including the terminating null byte.
84 If a wide character was encountered which could not be
85 converted,
86 .I (size_t)\ \-1
87 is returned.
88 .SH CONFORMING TO
89 C99.
90 .SH NOTES
91 The behavior of
92 .BR wcstombs ()
93 depends on the
94 .B LC_CTYPE
95 category of the
96 current locale.
97 .PP
98 The function
99 .BR wcsrtombs (3)
100 provides a thread safe interface to
101 the same functionality.
102 .SH SEE ALSO
103 .BR mbstowcs (3),
104 .BR wcsrtombs (3)