1WCSTOMBS(3) Linux Programmer's Manual WCSTOMBS(3)
2
3
4
6 wcstombs - convert a wide-character string to a multibyte string
7
9 #include <stdlib.h>
10
11 size_t wcstombs(char *restrict dest, const wchar_t *restrict src,
12 size_t n);
13
15 If dest is not NULL, the wcstombs() function converts the wide-charac‐
16 ter string src to a multibyte string starting at dest. At most n bytes
17 are written to dest. The sequence of characters placed in dest begins
18 in the initial shift state. The conversion can stop for three reasons:
19
20 1. A wide character has been encountered that can not be represented as
21 a multibyte sequence (according to the current locale). In this
22 case, (size_t) -1 is returned.
23
24 2. The length limit forces a stop. In this case, the number of bytes
25 written to dest is returned, but the shift state at this point is
26 lost.
27
28 3. The wide-character string has been completely converted, including
29 the terminating null wide character (L'\0'). In this case, the con‐
30 version ends in the initial shift state. The number of bytes writ‐
31 ten to dest, excluding the terminating null byte ('\0'), is re‐
32 turned.
33
34 The programmer must ensure that there is room for at least n bytes at
35 dest.
36
37 If dest is NULL, n is ignored, and the conversion proceeds as above,
38 except that the converted bytes are not written out to memory, and no
39 length limit exists.
40
41 In order to avoid the case 2 above, the programmer should make sure n
42 is greater than or equal to wcstombs(NULL,src,0)+1.
43
45 The wcstombs() function returns the number of bytes that make up the
46 converted part of a multibyte sequence, not including the terminating
47 null byte. If a wide character was encountered which could not be con‐
48 verted, (size_t) -1 is returned.
49
51 For an explanation of the terms used in this section, see at‐
52 tributes(7).
53
54 ┌────────────────────────────────────────────┬───────────────┬─────────┐
55 │Interface │ Attribute │ Value │
56 ├────────────────────────────────────────────┼───────────────┼─────────┤
57 │wcstombs() │ Thread safety │ MT-Safe │
58 └────────────────────────────────────────────┴───────────────┴─────────┘
59
61 POSIX.1-2001, POSIX.1-2008, C99.
62
64 The behavior of wcstombs() depends on the LC_CTYPE category of the cur‐
65 rent locale.
66
67 The function wcsrtombs(3) provides a better interface to the same func‐
68 tionality.
69
71 mblen(3), mbstowcs(3), mbtowc(3), wcsrtombs(3), wctomb(3)
72
74 This page is part of release 5.13 of the Linux man-pages project. A
75 description of the project, information about reporting bugs, and the
76 latest version of this page, can be found at
77 https://www.kernel.org/doc/man-pages/.
78
79
80
81GNU 2021-03-22 WCSTOMBS(3)