3 <<mbsrtowcs>>, <<mbsnrtowcs>>---convert a character string to a wide-character string
16 size_t mbsrtowcs(wchar_t *__restrict <[dst]>,
17 const char **__restrict <[src]>,
19 mbstate_t *__restrict <[ps]>);
22 size_t _mbsrtowcs_r(struct _reent *<[ptr]>, wchar_t *<[dst]>,
23 const char **<[src]>, size_t <[len]>,
27 size_t mbsnrtowcs(wchar_t *__ restrict <[dst]>,
28 const char **__restrict <[src]>, size_t <[nms]>,
29 size_t <[len]>, mbstate_t *__restrict <[ps]>);
32 size_t _mbsnrtowcs_r(struct _reent *<[ptr]>, wchar_t *<[dst]>,
33 const char **<[src]>, size_t <[nms]>,
34 size_t <[len]>, mbstate_t *<[ps]>);
37 The <<mbsrtowcs>> function converts a sequence of multibyte characters
38 pointed to indirectly by <[src]> into a sequence of corresponding wide
39 characters and stores at most <[len]> of them in the wchar_t array pointed
40 to by <[dst]>, until it encounters a terminating null character ('\0').
42 If <[dst]> is NULL, no characters are stored.
44 If <[dst]> is not NULL, the pointer pointed to by <[src]> is updated to point
45 to the character after the one that conversion stopped at. If conversion
46 stops because a null character is encountered, *<[src]> is set to NULL.
48 The mbstate_t argument, <[ps]>, is used to keep track of the shift state. If
49 it is NULL, <<mbsrtowcs>> uses an internal, static mbstate_t object, which
50 is initialized to the initial conversion state at program startup.
52 The <<mbsnrtowcs>> function behaves identically to <<mbsrtowcs>>, except that
53 conversion stops after reading at most <[nms]> bytes from the buffer pointed
57 The <<mbsrtowcs>> and <<mbsnrtowcs>> functions return the number of wide
58 characters stored in the array pointed to by <[dst]> if successful, otherwise
59 it returns (size_t)-1.
62 <<mbsrtowcs>> is defined by the C99 standard.
63 <<mbsnrtowcs>> is defined by the POSIX.1-2008 standard.
73 #ifdef _REENT_THREAD_LOCAL
74 _Thread_local _mbstate_t _tls_mbsrtowcs_state
;
78 _mbsnrtowcs_r (struct _reent
*r
,
95 ps
= &(_REENT_MBSRTOWCS_STATE(r
));
101 /* Ignore original len value and do not alter src pointer if the
102 dst pointer is NULL. */
111 bytes
= _mbrtowc_r (r
, ptr
, *src
, nms
, ps
);
117 ptr
= (dst
== NULL
) ? NULL
: ptr
+ 1;
120 else if (bytes
== -2)
133 _REENT_ERRNO(r
) = EILSEQ
;
143 mbsnrtowcs (wchar_t *__restrict dst
,
144 const char **__restrict src
,
147 mbstate_t *__restrict ps
)
149 return _mbsnrtowcs_r (_REENT
, dst
, src
, nms
, len
, ps
);
151 #endif /* !_REENT_ONLY */