1WCSNRTOMBS(3) Linux Programmer's Manual WCSNRTOMBS(3)
2
3
4
6 wcsnrtombs - convert a wide-character string to a multibyte string
7
9 #include <wchar.h>
10
11 size_t wcsnrtombs(char *restrict dest, const wchar_t **restrict src,
12 size_t nwc, size_t len, mbstate_t *restrict ps);
13
14 Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
15
16 wcsnrtombs():
17 Since glibc 2.10:
18 _POSIX_C_SOURCE >= 200809L
19 Before glibc 2.10:
20 _GNU_SOURCE
21
23 The wcsnrtombs() function is like the wcsrtombs(3) function, except
24 that the number of wide characters to be converted, starting at *src,
25 is limited to nwc.
26
27 If dest is not NULL, the wcsnrtombs() function converts at most nwc
28 wide characters from the wide-character string *src to a multibyte
29 string starting at dest. At most len bytes are written to dest. The
30 shift state *ps is updated. The conversion is effectively performed by
31 repeatedly calling wcrtomb(dest, *src, ps), as long as this call suc‐
32 ceeds, and then incrementing dest by the number of bytes written and
33 *src by one. The conversion can stop for three reasons:
34
35 1. A wide character has been encountered that can not be represented as
36 a multibyte sequence (according to the current locale). In this
37 case, *src is left pointing to the invalid wide character,
38 (size_t) -1 is returned, and errno is set to EILSEQ.
39
40 2. nwc wide characters have been converted without encountering a null
41 wide character (L'\0'), or the length limit forces a stop. In this
42 case, *src is left pointing to the next wide character to be con‐
43 verted, and the number of bytes written to dest is returned.
44
45 3. The wide-character string has been completely converted, including
46 the terminating null wide character (which has the side effect of
47 bringing back *ps to the initial state). In this case, *src is set
48 to NULL, and the number of bytes written to dest, excluding the ter‐
49 minating null byte ('\0'), is returned.
50
51 If dest is NULL, len is ignored, and the conversion proceeds as above,
52 except that the converted bytes are not written out to memory, and that
53 no destination length limit exists.
54
55 In both of the above cases, if ps is NULL, a static anonymous state
56 known only to the wcsnrtombs() function is used instead.
57
58 The programmer must ensure that there is room for at least len bytes at
59 dest.
60
62 The wcsnrtombs() function returns the number of bytes that make up the
63 converted part of multibyte sequence, not including the terminating
64 null byte. If a wide character was encountered which could not be con‐
65 verted, (size_t) -1 is returned, and errno set to EILSEQ.
66
68 For an explanation of the terms used in this section, see at‐
69 tributes(7).
70
71 ┌─────────────┬───────────────┬────────────────────────────────────────┐
72 │Interface │ Attribute │ Value │
73 ├─────────────┼───────────────┼────────────────────────────────────────┤
74 │wcsnrtombs() │ Thread safety │ MT-Unsafe race:wcsnrtombs/!ps │
75 └─────────────┴───────────────┴────────────────────────────────────────┘
76
78 POSIX.1-2008.
79
81 The behavior of wcsnrtombs() depends on the LC_CTYPE category of the
82 current locale.
83
84 Passing NULL as ps is not multithread safe.
85
87 iconv(3), mbsinit(3), wcsrtombs(3)
88
90 This page is part of release 5.13 of the Linux man-pages project. A
91 description of the project, information about reporting bugs, and the
92 latest version of this page, can be found at
93 https://www.kernel.org/doc/man-pages/.
94
95
96
97GNU 2021-03-22 WCSNRTOMBS(3)