]>
Commit | Line | Data |
---|---|---|
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 | 18 | wcstombs \- 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 |
26 | If |
27 | .I dest | |
b437fdd9 | 28 | is not NULL, the |
60a90ecd MK |
29 | .BR wcstombs () |
30 | function converts | |
40aa0db0 MK |
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 . | |
3942b6bc MK |
39 | The sequence of characters placed in |
40 | .IR dest | |
41 | begins in the initial shift state. | |
c13182ef | 42 | The conversion can stop for three reasons: |
db59590e MK |
43 | .IP 1. 3 |
44 | A wide character has been encountered that can not be represented as a | |
c13182ef | 45 | multibyte sequence (according to the current locale). |
9218ef3d | 46 | In this case, |
009df872 | 47 | .I (size_t)\ \-1 |
7d2cb9d5 | 48 | is returned. |
db59590e | 49 | .IP 2. |
db59590e | 50 | The length limit forces a stop. |
441efbb7 | 51 | In this case, the number of bytes written to |
40aa0db0 MK |
52 | .I dest |
53 | is returned, but the shift state at this point is lost. | |
db59590e MK |
54 | .IP 3. |
55 | The wide-character string has been completely converted, including the | |
e9c23bc6 | 56 | terminating null wide character (L\(aq\\0\(aq). |
3942b6bc | 57 | In this case, the conversion ends in the initial shift state. |
40aa0db0 MK |
58 | The number of bytes written to |
59 | .IR dest , | |
3c81e148 | 60 | excluding the terminating null byte (\(aq\\0\(aq), is returned. |
fea681da | 61 | .PP |
40aa0db0 MK |
62 | The programmer must ensure that there is room for at least |
63 | .I n | |
64 | bytes | |
65 | at | |
66 | .IR dest . | |
fea681da | 67 | .PP |
40aa0db0 | 68 | If |
51700fd7 | 69 | .IR dest |
40aa0db0 MK |
70 | is NULL, |
71 | .I n | |
72 | is ignored, and the conversion proceeds as | |
fb186734 | 73 | above, except that the converted bytes are not written out to memory, |
d75efe73 | 74 | and no length limit exists. |
fea681da | 75 | .PP |
40aa0db0 MK |
76 | In order to avoid the case 2 above, the programmer should make sure |
77 | .I n | |
d75efe73 | 78 | is greater than or equal to |
40aa0db0 | 79 | .IR "wcstombs(NULL,src,0)+1" . |
47297adb | 80 | .SH RETURN VALUE |
60a90ecd MK |
81 | The |
82 | .BR wcstombs () | |
83 | function returns the number of bytes that make up the | |
d75efe73 MK |
84 | converted part of a multibyte sequence, |
85 | not including the terminating null byte. | |
fb186734 | 86 | If a wide character was encountered which could not be |
7d2cb9d5 | 87 | converted, |
009df872 | 88 | .I (size_t)\ \-1 |
7d2cb9d5 | 89 | is returned. |
b640fcfa MS |
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 | |
847e0d88 | 102 | .sp 1 |
47297adb | 103 | .SH CONFORMING TO |
6d2e3caf | 104 | POSIX.1-2001, POSIX.1-2008, C99. |
fea681da | 105 | .SH NOTES |
d9bfdb9c | 106 | The behavior of |
60a90ecd | 107 | .BR wcstombs () |
1274071a MK |
108 | depends on the |
109 | .B LC_CTYPE | |
110 | category of the | |
fea681da MK |
111 | current locale. |
112 | .PP | |
60a90ecd MK |
113 | The function |
114 | .BR wcsrtombs (3) | |
fdcc06ee | 115 | provides 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) |