]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man3/wcstombs.3
err.3: EXAMPLES: use EXIT_FAILURE rather than 1 as exit status
[thirdparty/man-pages.git] / 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 2019-03-06 "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 .PP
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 sequence of characters placed in
40 .IR dest
41 begins in the initial shift state.
42 The conversion can stop for three reasons:
43 .IP 1. 3
44 A wide character has been encountered that can not be represented as a
45 multibyte sequence (according to the current locale).
46 In this case,
47 .I (size_t)\ \-1
48 is returned.
49 .IP 2.
50 The length limit forces a stop.
51 In this case, the number of bytes written to
52 .I dest
53 is returned, but the shift state at this point is lost.
54 .IP 3.
55 The wide-character string has been completely converted, including the
56 terminating null wide character (L\(aq\e0\(aq).
57 In this case, the conversion ends in the initial shift state.
58 The number of bytes written to
59 .IR dest ,
60 excluding the terminating null byte (\(aq\e0\(aq), is returned.
61 .PP
62 The programmer must ensure that there is room for at least
63 .I n
64 bytes
65 at
66 .IR dest .
67 .PP
68 If
69 .IR dest
70 is NULL,
71 .I n
72 is ignored, and the conversion proceeds as
73 above, except that the converted bytes are not written out to memory,
74 and no length limit exists.
75 .PP
76 In order to avoid the case 2 above, the programmer should make sure
77 .I n
78 is greater than or equal to
79 .IR "wcstombs(NULL,src,0)+1" .
80 .SH RETURN VALUE
81 The
82 .BR wcstombs ()
83 function returns the number of bytes that make up the
84 converted part of a multibyte sequence,
85 not including the terminating null byte.
86 If a wide character was encountered which could not be
87 converted,
88 .I (size_t)\ \-1
89 is returned.
90 .SH ATTRIBUTES
91 For an explanation of the terms used in this section, see
92 .BR attributes (7).
93 .TS
94 allbox;
95 lb lb lb
96 l l l.
97 Interface Attribute Value
98 T{
99 .BR wcstombs ()
100 T} Thread safety MT-Safe
101 .TE
102 .sp 1
103 .SH CONFORMING TO
104 POSIX.1-2001, POSIX.1-2008, C99.
105 .SH NOTES
106 The behavior of
107 .BR wcstombs ()
108 depends on the
109 .B LC_CTYPE
110 category of the
111 current locale.
112 .PP
113 The function
114 .BR wcsrtombs (3)
115 provides a better interface to the same functionality.
116 .SH SEE ALSO
117 .BR mblen (3),
118 .BR mbstowcs (3),
119 .BR mbtowc (3),
120 .BR wcsrtombs (3),
121 .BR wctomb (3)