#include <sys/cdefs.h>
__FBSDID("$FreeBSD: src/lib/libc/locale/mbsnrtowcs.c,v 1.1 2004/07/21 10:54:57 tjr Exp $");
+#include "xlocale_private.h"
+
#include <errno.h>
#include <limits.h>
#include <stdlib.h>
#include "mblocal.h"
size_t
-mbsnrtowcs(wchar_t * __restrict dst, const char ** __restrict src,
- size_t nms, size_t len, mbstate_t * __restrict ps)
+mbsnrtowcs_l(wchar_t * __restrict dst, const char ** __restrict src,
+ size_t nms, size_t len, mbstate_t * __restrict ps, locale_t loc)
{
- static mbstate_t mbs;
-
+ NORMALIZE_LOCALE(loc);
if (ps == NULL)
- ps = &mbs;
- return (__mbsnrtowcs(dst, src, nms, len, ps));
+ ps = &loc->__mbs_mbsnrtowcs;
+ return (loc->__lc_ctype->__mbsnrtowcs(dst, src, nms, len, ps, loc));
}
size_t
-__mbsnrtowcs_std(wchar_t * __restrict dst, const char ** __restrict src,
+mbsnrtowcs(wchar_t * __restrict dst, const char ** __restrict src,
size_t nms, size_t len, mbstate_t * __restrict ps)
+{
+ return mbsnrtowcs_l(dst, src, nms, len, ps, __current_locale());
+}
+
+__private_extern__ size_t
+__mbsnrtowcs_std(wchar_t * __restrict dst, const char ** __restrict src,
+ size_t nms, size_t len, mbstate_t * __restrict ps, locale_t loc)
{
const char *s;
size_t nchr;
wchar_t wc;
size_t nb;
+ size_t (*__mbrtowc)(wchar_t * __restrict, const char * __restrict,
+ size_t, mbstate_t * __restrict, locale_t)
+ = loc->__lc_ctype->__mbrtowc;
s = *src;
nchr = 0;
if (dst == NULL) {
for (;;) {
- if ((nb = __mbrtowc(&wc, s, nms, ps)) == (size_t)-1)
+ if ((nb = __mbrtowc(&wc, s, nms, ps, loc)) == (size_t)-1)
/* Invalid sequence - mbrtowc() sets errno. */
return ((size_t)-1);
else if (nb == 0 || nb == (size_t)-2)
}
while (len-- > 0) {
- if ((nb = __mbrtowc(dst, s, nms, ps)) == (size_t)-1) {
+ if ((nb = __mbrtowc(dst, s, nms, ps, loc)) == (size_t)-1) {
*src = s;
return ((size_t)-1);
} else if (nb == (size_t)-2) {