]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man3/wcstombs.3
strcmp.3: Clarify that strcmp() is not locale aware
[thirdparty/man-pages.git] / man3 / wcstombs.3
CommitLineData
fea681da
MK
1.\" Copyright (c) Bruno Haible <haible@clisp.cons.org>
2.\"
89e3ffe9 3.\" %%%LICENSE_START(GPLv2+_DOC_ONEPARA)
fea681da
MK
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.
fe382ebf 8.\" %%%LICENSE_END
fea681da
MK
9.\"
10.\" References consulted:
11.\" GNU glibc-2 source code and manual
12.\" Dinkumware C library reference http://www.dinkumware.com/
008f1ecc 13.\" OpenGroup's Single UNIX specification http://www.UNIX-systems.org/online.html
fea681da
MK
14.\" ISO/IEC 9899:1999
15.\"
4b8c67d9 16.TH WCSTOMBS 3 2017-09-15 "GNU" "Linux Programmer's Manual"
fea681da 17.SH NAME
d0f17b57 18wcstombs \- convert a wide-character string to a multibyte string
fea681da
MK
19.SH SYNOPSIS
20.nf
21.B #include <stdlib.h>
68e4db0a 22.PP
fea681da
MK
23.BI "size_t wcstombs(char *" dest ", const wchar_t *" src ", size_t " n );
24.fi
25.SH DESCRIPTION
40aa0db0
MK
26If
27.I dest
b437fdd9 28is not NULL, the
60a90ecd
MK
29.BR wcstombs ()
30function converts
40aa0db0
MK
31the wide-character string
32.I src
33to a multibyte string starting at
34.IR dest .
35At most
36.I n
37bytes are written to
38.IR dest .
3942b6bc
MK
39The sequence of characters placed in
40.IR dest
41begins in the initial shift state.
c13182ef 42The conversion can stop for three reasons:
db59590e
MK
43.IP 1. 3
44A wide character has been encountered that can not be represented as a
c13182ef 45multibyte sequence (according to the current locale).
9218ef3d 46In this case,
009df872 47.I (size_t)\ \-1
7d2cb9d5 48is returned.
db59590e 49.IP 2.
db59590e 50The length limit forces a stop.
441efbb7 51In this case, the number of bytes written to
40aa0db0
MK
52.I dest
53is returned, but the shift state at this point is lost.
db59590e
MK
54.IP 3.
55The wide-character string has been completely converted, including the
e9c23bc6 56terminating null wide character (L\(aq\\0\(aq).
3942b6bc 57In this case, the conversion ends in the initial shift state.
40aa0db0
MK
58The number of bytes written to
59.IR dest ,
3c81e148 60excluding the terminating null byte (\(aq\\0\(aq), is returned.
fea681da 61.PP
40aa0db0
MK
62The programmer must ensure that there is room for at least
63.I n
64bytes
65at
66.IR dest .
fea681da 67.PP
40aa0db0 68If
51700fd7 69.IR dest
40aa0db0
MK
70is NULL,
71.I n
72is ignored, and the conversion proceeds as
fb186734 73above, except that the converted bytes are not written out to memory,
d75efe73 74and no length limit exists.
fea681da 75.PP
40aa0db0
MK
76In order to avoid the case 2 above, the programmer should make sure
77.I n
d75efe73 78is greater than or equal to
40aa0db0 79.IR "wcstombs(NULL,src,0)+1" .
47297adb 80.SH RETURN VALUE
60a90ecd
MK
81The
82.BR wcstombs ()
83function returns the number of bytes that make up the
d75efe73
MK
84converted part of a multibyte sequence,
85not including the terminating null byte.
fb186734 86If a wide character was encountered which could not be
7d2cb9d5 87converted,
009df872 88.I (size_t)\ \-1
7d2cb9d5 89is returned.
b640fcfa
MS
90.SH ATTRIBUTES
91For an explanation of the terms used in this section, see
92.BR attributes (7).
93.TS
94allbox;
95lb lb lb
96l l l.
97Interface Attribute Value
98T{
99.BR wcstombs ()
100T} Thread safety MT-Safe
101.TE
847e0d88 102.sp 1
47297adb 103.SH CONFORMING TO
6d2e3caf 104POSIX.1-2001, POSIX.1-2008, C99.
fea681da 105.SH NOTES
d9bfdb9c 106The behavior of
60a90ecd 107.BR wcstombs ()
1274071a
MK
108depends on the
109.B LC_CTYPE
110category of the
fea681da
MK
111current locale.
112.PP
60a90ecd
MK
113The function
114.BR wcsrtombs (3)
fdcc06ee 115provides a better interface to the same functionality.
47297adb 116.SH SEE ALSO
4670051b 117.BR mblen (3),
49438ab7 118.BR mbstowcs (3),
ca38b869 119.BR mbtowc (3),
e37e3282 120.BR wcsrtombs (3)
e8b81d34 121.BR wctomb (3)