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