1wcrtomb(3) Library Functions Manual wcrtomb(3)
2
3
4
6 wcrtomb - convert a wide character to a multibyte sequence
7
9 Standard C library (libc, -lc)
10
12 #include <wchar.h>
13
14 size_t wcrtomb(char *restrict s, wchar_t wc, mbstate_t *restrict ps);
15
17 The main case for this function is when s is not NULL and wc is not a
18 null wide character (L'\0'). In this case, the wcrtomb() function con‐
19 verts the wide character wc to its multibyte representation and stores
20 it at the beginning of the character array pointed to by s. It updates
21 the shift state *ps, and returns the length of said multibyte represen‐
22 tation, that is, the number of bytes written at s.
23
24 A different case is when s is not NULL, but wc is a null wide character
25 (L'\0'). In this case, the wcrtomb() function stores at the character
26 array pointed to by s the shift sequence needed to bring *ps back to
27 the initial state, followed by a '\0' byte. It updates the shift state
28 *ps (i.e., brings it into the initial state), and returns the length of
29 the shift sequence plus one, that is, the number of bytes written at s.
30
31 A third case is when s is NULL. In this case, wc is ignored, and the
32 function effectively returns
33
34 wcrtomb(buf, L'\0', ps)
35
36 where buf is an internal anonymous buffer.
37
38 In all of the above cases, if ps is NULL, a static anonymous state
39 known only to the wcrtomb() function is used instead.
40
42 The wcrtomb() function returns the number of bytes that have been or
43 would have been written to the byte array at s. If wc can not be rep‐
44 resented as a multibyte sequence (according to the current locale),
45 (size_t) -1 is returned, and errno set to EILSEQ.
46
48 For an explanation of the terms used in this section, see at‐
49 tributes(7).
50
51 ┌─────────────────────────┬───────────────┬────────────────────────────┐
52 │Interface │ Attribute │ Value │
53 ├─────────────────────────┼───────────────┼────────────────────────────┤
54 │wcrtomb() │ Thread safety │ MT-Unsafe race:wcrtomb/!ps │
55 └─────────────────────────┴───────────────┴────────────────────────────┘
56
58 C11, POSIX.1-2008.
59
61 POSIX.1-2001, C99.
62
64 The behavior of wcrtomb() depends on the LC_CTYPE category of the
65 current locale.
66
67 Passing NULL as ps is not multithread safe.
68
70 mbsinit(3), wcsrtombs(3)
71
72
73
74Linux man-pages 6.05 2023-07-20 wcrtomb(3)