]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man3/wcstombs.3
MB_CUR_MAX.3, MB_LEN_MAX.3, btowc.3, fgetwc.3, fgetws.3, fputwc.3, fputws.3, fwide...
[thirdparty/man-pages.git] / man3 / wcstombs.3
CommitLineData
fea681da
MK
1.\" Copyright (c) Bruno Haible <haible@clisp.cons.org>
2.\"
fe382ebf 3.\" %%%LICENSE_START(GPLv2+_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.\"
3c81e148 16.TH WCSTOMBS 3 2011-10-16 "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>
22.sp
23.BI "size_t wcstombs(char *" dest ", const wchar_t *" src ", size_t " n );
24.fi
25.SH DESCRIPTION
60a90ecd
MK
26If \fIdest\fP is not a NULL pointer, the
27.BR wcstombs ()
28function converts
fea681da 29the wide-character string \fIsrc\fP to a multibyte string starting at
c13182ef
MK
30\fIdest\fP.
31At most \fIn\fP bytes are written to \fIdest\fP.
32The conversion
33starts in the initial state.
34The conversion can stop for three reasons:
fea681da
MK
35.PP
361. A wide character has been encountered that can not be represented as a
c13182ef
MK
37multibyte sequence (according to the current locale).
38In this case
009df872 39.I (size_t)\ \-1
7d2cb9d5 40is returned.
fea681da 41.PP
c13182ef
MK
422. The length limit forces a stop.
43In this case the number of bytes written to
fea681da
MK
44\fIdest\fP is returned, but the shift state at this point is lost.
45.PP
463. The wide-character string has been completely converted, including the
e9c23bc6 47terminating null wide character (L\(aq\\0\(aq).
c13182ef 48In this case the conversion ends in the initial state.
f81fb444 49The number of bytes written to \fIdest\fP,
3c81e148 50excluding the terminating null byte (\(aq\\0\(aq), is returned.
fea681da
MK
51.PP
52The programmer must ensure that there is room for at least \fIn\fP bytes
53at \fIdest\fP.
54.PP
55If \fIdest\fP is NULL, \fIn\fP is ignored, and the conversion proceeds as
fb186734
MK
56above, except that the converted bytes are not written out to memory,
57and that no length limit exists.
fea681da
MK
58.PP
59In order to avoid the case 2 above, the programmer should make sure \fIn\fP
60is greater or equal to \fIwcstombs(NULL,src,0)+1\fP.
47297adb 61.SH RETURN VALUE
60a90ecd
MK
62The
63.BR wcstombs ()
64function returns the number of bytes that make up the
fea681da 65converted part of multibyte sequence, not including the terminating null byte.
fb186734 66If a wide character was encountered which could not be
7d2cb9d5 67converted,
009df872 68.I (size_t)\ \-1
7d2cb9d5 69is returned.
47297adb 70.SH CONFORMING TO
68e1685c 71C99.
fea681da 72.SH NOTES
d9bfdb9c 73The behavior of
60a90ecd 74.BR wcstombs ()
1274071a
MK
75depends on the
76.B LC_CTYPE
77category of the
fea681da
MK
78current locale.
79.PP
60a90ecd
MK
80The function
81.BR wcsrtombs (3)
82provides a thread safe interface to
91fe9d5c 83the same functionality.
47297adb 84.SH SEE ALSO
49438ab7 85.BR mbstowcs (3),
e37e3282 86.BR wcsrtombs (3)