#include <sys/cdefs.h>
__FBSDID("$FreeBSD: src/lib/libc/locale/mbtowc.c,v 1.11 2004/07/29 06:18:40 tjr Exp $");
+#include "xlocale_private.h"
+
#include <stdlib.h>
#include <wchar.h>
#include "mblocal.h"
int
-mbtowc(wchar_t * __restrict pwc, const char * __restrict s, size_t n)
+mbtowc_l(wchar_t * __restrict pwc, const char * __restrict s, size_t n,
+ locale_t loc)
{
static const mbstate_t initial;
- static mbstate_t mbs;
size_t rval;
+ NORMALIZE_LOCALE(loc);
if (s == NULL) {
/* No support for state dependent encodings. */
- mbs = initial;
+ loc->__mbs_mbtowc = initial;
return (0);
}
- rval = __mbrtowc(pwc, s, n, &mbs);
+ rval = loc->__lc_ctype->__mbrtowc(pwc, s, n, &loc->__mbs_mbtowc, loc);
if (rval == (size_t)-1 || rval == (size_t)-2)
return (-1);
return ((int)rval);
}
+
+int
+mbtowc(wchar_t * __restrict pwc, const char * __restrict s, size_t n)
+{
+ return mbtowc_l(pwc, s, n, __current_locale());
+}