sigaction.2: Minor clean-ups to Peter Collingbourne's patch
[man-pages.git] / man3 / wcstombs.3
blob04c01aacde9c584ab8e1c3f589d8094b1ba68411
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  2021-03-22 "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 *restrict " dest ", const wchar_t *restrict " src ,
24 .BI "                size_t " n );
25 .fi
26 .SH DESCRIPTION
28 .I dest
29 is not NULL, the
30 .BR wcstombs ()
31 function converts
32 the wide-character string
33 .I src
34 to a multibyte string starting at
35 .IR dest .
36 At most
37 .I n
38 bytes are written to
39 .IR dest .
40 The sequence of characters placed in
41 .IR dest
42 begins in the initial shift state.
43 The conversion can stop for three reasons:
44 .IP 1. 3
45 A wide character has been encountered that can not be represented as a
46 multibyte sequence (according to the current locale).
47 In this case,
48 .I (size_t)\ \-1
49 is returned.
50 .IP 2.
51 The length limit forces a stop.
52 In this case, the number of bytes written to
53 .I dest
54 is returned, but the shift state at this point is lost.
55 .IP 3.
56 The wide-character string has been completely converted, including the
57 terminating null wide character (L\(aq\e0\(aq).
58 In this case, the conversion ends in the initial shift state.
59 The number of bytes written to
60 .IR dest ,
61 excluding the terminating null byte (\(aq\e0\(aq), is returned.
62 .PP
63 The programmer must ensure that there is room for at least
64 .I n
65 bytes
67 .IR dest .
68 .PP
70 .IR dest
71 is NULL,
72 .I n
73 is ignored, and the conversion proceeds as
74 above, except that the converted bytes are not written out to memory,
75 and no length limit exists.
76 .PP
77 In order to avoid the case 2 above, the programmer should make sure
78 .I n
79 is greater than or equal to
80 .IR "wcstombs(NULL,src,0)+1" .
81 .SH RETURN VALUE
82 The
83 .BR wcstombs ()
84 function returns the number of bytes that make up the
85 converted part of a multibyte sequence,
86 not including the terminating null byte.
87 If a wide character was encountered which could not be
88 converted,
89 .I (size_t)\ \-1
90 is returned.
91 .SH ATTRIBUTES
92 For an explanation of the terms used in this section, see
93 .BR attributes (7).
94 .ad l
95 .nh
96 .TS
97 allbox;
98 lbx lb lb
99 l l l.
100 Interface       Attribute       Value
102 .BR wcstombs ()
103 T}      Thread safety   MT-Safe
107 .sp 1
108 .SH CONFORMING TO
109 POSIX.1-2001, POSIX.1-2008, C99.
110 .SH NOTES
111 The behavior of
112 .BR wcstombs ()
113 depends on the
114 .B LC_CTYPE
115 category of the
116 current locale.
118 The function
119 .BR wcsrtombs (3)
120 provides a better interface to the same functionality.
121 .SH SEE ALSO
122 .BR mblen (3),
123 .BR mbstowcs (3),
124 .BR mbtowc (3),
125 .BR wcsrtombs (3),
126 .BR wctomb (3)