*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/stdio/fgetwc.c,v 1.12 2004/07/20 08:27:27 tjr Exp $");
+__FBSDID("$FreeBSD: src/lib/libc/stdio/fgetwc.c,v 1.13 2008/04/17 22:17:53 jhb Exp $");
+
+#include "xlocale_private.h"
#include "namespace.h"
#include <errno.h>
FLOCKFILE(fp);
ORIENT(fp, 1);
- r = __fgetwc(fp);
+ r = __fgetwc(fp, __current_locale());
+ FUNLOCKFILE(fp);
+
+ return (r);
+}
+
+wint_t
+fgetwc_l(FILE *fp, locale_t loc)
+{
+ wint_t r;
+
+ NORMALIZE_LOCALE(loc);
+ FLOCKFILE(fp);
+ ORIENT(fp, 1);
+ r = __fgetwc(fp, loc);
FUNLOCKFILE(fp);
return (r);
* Non-MT-safe version.
*/
wint_t
-__fgetwc(FILE *fp)
+__fgetwc(FILE *fp, locale_t loc)
{
wchar_t wc;
size_t nconv;
+ struct __xlocale_st_runelocale *xrl = loc->__lc_ctype;
+ size_t (*__mbrtowc)(wchar_t * __restrict, const char * __restrict, size_t, mbstate_t * __restrict, locale_t) = xrl->__mbrtowc;
if (fp->_r <= 0 && __srefill(fp))
return (WEOF);
- if (MB_CUR_MAX == 1) {
+ if (xrl->__mb_cur_max == 1) {
/* Fast path for single-byte encodings. */
wc = *fp->_p++;
fp->_r--;
return (wc);
}
do {
- nconv = __mbrtowc(&wc, fp->_p, fp->_r, &fp->_extra->mbstate);
+ nconv = __mbrtowc(&wc, (char*)fp->_p, fp->_r, &fp->_mbstate, loc);
if (nconv == (size_t)-1)
break;
else if (nconv == (size_t)-2)