1wcsrtombs(3) Library Functions Manual wcsrtombs(3)
2
3
4
6 wcsrtombs - convert a wide-character string to a multibyte string
7
9 Standard C library (libc, -lc)
10
12 #include <wchar.h>
13
14 size_t wcsrtombs(char dest[restrict .len], const wchar_t **restrict src,
15 size_t len, mbstate_t *restrict ps);
16
18 If dest is not NULL, the wcsrtombs() function converts the wide-charac‐
19 ter string *src to a multibyte string starting at dest. At most len
20 bytes are written to dest. The shift state *ps is updated. The con‐
21 version is effectively performed by repeatedly calling wcrtomb(dest,
22 *src, ps), as long as this call succeeds, and then incrementing dest by
23 the number of bytes written and *src by one. The conversion can stop
24 for three reasons:
25
26 • A wide character has been encountered that can not be represented as
27 a multibyte sequence (according to the current locale). In this
28 case, *src is left pointing to the invalid wide character,
29 (size_t) -1 is returned, and errno is set to EILSEQ.
30
31 • The length limit forces a stop. In this case, *src is left pointing
32 to the next wide character to be converted, and the number of bytes
33 written to dest is returned.
34
35 • The wide-character string has been completely converted, including
36 the terminating null wide character (L'\0'), which has the side ef‐
37 fect of bringing back *ps to the initial state. In this case, *src
38 is set to NULL, and the number of bytes written to dest, excluding
39 the terminating null byte ('\0'), is returned.
40
41 If dest is NULL, len is ignored, and the conversion proceeds as above,
42 except that the converted bytes are not written out to memory, and that
43 no length limit exists.
44
45 In both of the above cases, if ps is NULL, a static anonymous state
46 known only to the wcsrtombs() function is used instead.
47
48 The programmer must ensure that there is room for at least len bytes at
49 dest.
50
52 The wcsrtombs() function returns the number of bytes that make up the
53 converted part of multibyte sequence, not including the terminating
54 null byte. If a wide character was encountered which could not be con‐
55 verted, (size_t) -1 is returned, and errno set to EILSEQ.
56
58 For an explanation of the terms used in this section, see at‐
59 tributes(7).
60
61 ┌────────────┬───────────────┬─────────────────────────────────────────┐
62 │Interface │ Attribute │ Value │
63 ├────────────┼───────────────┼─────────────────────────────────────────┤
64 │wcsrtombs() │ Thread safety │ MT-Unsafe race:wcsrtombs/!ps │
65 └────────────┴───────────────┴─────────────────────────────────────────┘
66
68 C11, POSIX.1-2008.
69
71 POSIX.1-2001, C99.
72
74 The behavior of wcsrtombs() depends on the LC_CTYPE category of the
75 current locale.
76
77 Passing NULL as ps is not multithread safe.
78
80 iconv(3), mbsinit(3), wcrtomb(3), wcsnrtombs(3), wcstombs(3)
81
82
83
84Linux man-pages 6.05 2023-07-20 wcsrtombs(3)