X-Git-Url: https://git.saurik.com/apple/libc.git/blobdiff_plain/3d9156a7a519a5e3aa1b92e9d9d4b991f1aed7ff..HEAD:/stdio/FreeBSD/fgetwc.c diff --git a/stdio/FreeBSD/fgetwc.c b/stdio/FreeBSD/fgetwc.c index f4a273a..709244f 100644 --- a/stdio/FreeBSD/fgetwc.c +++ b/stdio/FreeBSD/fgetwc.c @@ -25,7 +25,9 @@ */ #include -__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 @@ -47,7 +49,21 @@ fgetwc(FILE *fp) 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); @@ -57,21 +73,23 @@ fgetwc(FILE *fp) * 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)