]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man3/wcstombs.3
7403580eae5f60791b77c3cdd7303d31ee206c18
[thirdparty/man-pages.git] / man3 / wcstombs.3
1 .\" Copyright (c) Bruno Haible <haible@clisp.cons.org>
2 .\"
3 .\" SPDX-License-Identifier: GPL-2.0-or-later
4 .\"
5 .\" References consulted:
6 .\" GNU glibc-2 source code and manual
7 .\" Dinkumware C library reference http://www.dinkumware.com/
8 .\" OpenGroup's Single UNIX specification http://www.UNIX-systems.org/online.html
9 .\" ISO/IEC 9899:1999
10 .\"
11 .TH WCSTOMBS 3 2021-03-22 "GNU" "Linux Programmer's Manual"
12 .SH NAME
13 wcstombs \- convert a wide-character string to a multibyte string
14 .SH LIBRARY
15 Standard C library
16 .RI ( libc ", " \-lc )
17 .SH SYNOPSIS
18 .nf
19 .B #include <stdlib.h>
20 .PP
21 .BI "size_t wcstombs(char *restrict " dest ", const wchar_t *restrict " src ,
22 .BI " size_t " n );
23 .fi
24 .SH DESCRIPTION
25 If
26 .I dest
27 is not NULL, the
28 .BR wcstombs ()
29 function converts
30 the wide-character string
31 .I src
32 to a multibyte string starting at
33 .IR dest .
34 At most
35 .I n
36 bytes are written to
37 .IR dest .
38 The sequence of characters placed in
39 .IR dest
40 begins in the initial shift state.
41 The conversion can stop for three reasons:
42 .IP 1. 3
43 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 .IP 2.
49 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 .IP 3.
54 The wide-character string has been completely converted, including the
55 terminating null wide character (L\(aq\e0\(aq).
56 In this case, the conversion ends in the initial shift state.
57 The number of bytes written to
58 .IR dest ,
59 excluding the terminating null byte (\(aq\e0\(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 ATTRIBUTES
90 For an explanation of the terms used in this section, see
91 .BR attributes (7).
92 .ad l
93 .nh
94 .TS
95 allbox;
96 lbx lb lb
97 l l l.
98 Interface Attribute Value
99 T{
100 .BR wcstombs ()
101 T} Thread safety MT-Safe
102 .TE
103 .hy
104 .ad
105 .sp 1
106 .SH CONFORMING TO
107 POSIX.1-2001, POSIX.1-2008, C99.
108 .SH NOTES
109 The behavior of
110 .BR wcstombs ()
111 depends on the
112 .B LC_CTYPE
113 category of the
114 current locale.
115 .PP
116 The function
117 .BR wcsrtombs (3)
118 provides a better interface to the same functionality.
119 .SH SEE ALSO
120 .BR mblen (3),
121 .BR mbstowcs (3),
122 .BR mbtowc (3),
123 .BR wcsrtombs (3),
124 .BR wctomb (3)