]>
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 | .\" | |
3c81e148 | 16 | .TH WCSTOMBS 3 2011-10-16 "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> | |
22 | .sp | |
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 | |
28 | is not a NULL pointer, 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 . | |
c13182ef MK |
39 | The conversion |
40 | starts in the initial state. | |
41 | The conversion can stop for three reasons: | |
fea681da MK |
42 | .PP |
43 | 1. A wide character has been encountered that can not be represented as a | |
c13182ef MK |
44 | multibyte sequence (according to the current locale). |
45 | In this case | |
009df872 | 46 | .I (size_t)\ \-1 |
7d2cb9d5 | 47 | is returned. |
fea681da | 48 | .PP |
c13182ef MK |
49 | 2. The length limit forces a stop. |
50 | In this case the number of bytes written to | |
40aa0db0 MK |
51 | .I dest |
52 | is returned, but the shift state at this point is lost. | |
fea681da MK |
53 | .PP |
54 | 3. The wide-character string has been completely converted, including the | |
e9c23bc6 | 55 | terminating null wide character (L\(aq\\0\(aq). |
c13182ef | 56 | In this case the conversion ends in the initial state. |
40aa0db0 MK |
57 | The number of bytes written to |
58 | .IR dest , | |
3c81e148 | 59 | excluding the terminating null byte (\(aq\\0\(aq), is returned. |
fea681da | 60 | .PP |
40aa0db0 MK |
61 | The programmer must ensure that there is room for at least |
62 | .I n | |
63 | bytes | |
64 | at | |
65 | .IR dest . | |
fea681da | 66 | .PP |
40aa0db0 | 67 | If |
51700fd7 | 68 | .IR dest |
40aa0db0 MK |
69 | is NULL, |
70 | .I n | |
71 | is ignored, and the conversion proceeds as | |
fb186734 MK |
72 | above, except that the converted bytes are not written out to memory, |
73 | and that no length limit exists. | |
fea681da | 74 | .PP |
40aa0db0 MK |
75 | In order to avoid the case 2 above, the programmer should make sure |
76 | .I n | |
77 | is greater or equal to | |
78 | .IR "wcstombs(NULL,src,0)+1" . | |
47297adb | 79 | .SH RETURN VALUE |
60a90ecd MK |
80 | The |
81 | .BR wcstombs () | |
82 | function returns the number of bytes that make up the | |
fea681da | 83 | converted part of multibyte sequence, not including the terminating null byte. |
fb186734 | 84 | If a wide character was encountered which could not be |
7d2cb9d5 | 85 | converted, |
009df872 | 86 | .I (size_t)\ \-1 |
7d2cb9d5 | 87 | is returned. |
47297adb | 88 | .SH CONFORMING TO |
68e1685c | 89 | C99. |
fea681da | 90 | .SH NOTES |
d9bfdb9c | 91 | The behavior of |
60a90ecd | 92 | .BR wcstombs () |
1274071a MK |
93 | depends on the |
94 | .B LC_CTYPE | |
95 | category of the | |
fea681da MK |
96 | current locale. |
97 | .PP | |
60a90ecd MK |
98 | The function |
99 | .BR wcsrtombs (3) | |
100 | provides a thread safe interface to | |
91fe9d5c | 101 | the same functionality. |
47297adb | 102 | .SH SEE ALSO |
49438ab7 | 103 | .BR mbstowcs (3), |
e37e3282 | 104 | .BR wcsrtombs (3) |