]> git.saurik.com Git - apple/libc.git/blob - stdio/FreeBSD/fgetwc.c.patch
eec75c7ad9236f964df6dedd3ded0827e2fb8a2b
[apple/libc.git] / stdio / FreeBSD / fgetwc.c.patch
1 --- fgetwc.c.bsdnew 2009-11-11 13:33:05.000000000 -0800
2 +++ fgetwc.c 2009-11-11 13:43:19.000000000 -0800
3 @@ -27,6 +27,8 @@
4 #include <sys/cdefs.h>
5 __FBSDID("$FreeBSD: src/lib/libc/stdio/fgetwc.c,v 1.13 2008/04/17 22:17:53 jhb Exp $");
6
7 +#include "xlocale_private.h"
8 +
9 #include "namespace.h"
10 #include <errno.h>
11 #include <stdio.h>
12 @@ -47,7 +49,21 @@ fgetwc(FILE *fp)
13
14 FLOCKFILE(fp);
15 ORIENT(fp, 1);
16 - r = __fgetwc(fp);
17 + r = __fgetwc(fp, __current_locale());
18 + FUNLOCKFILE(fp);
19 +
20 + return (r);
21 +}
22 +
23 +wint_t
24 +fgetwc_l(FILE *fp, locale_t loc)
25 +{
26 + wint_t r;
27 +
28 + NORMALIZE_LOCALE(loc);
29 + FLOCKFILE(fp);
30 + ORIENT(fp, 1);
31 + r = __fgetwc(fp, loc);
32 FUNLOCKFILE(fp);
33
34 return (r);
35 @@ -57,21 +73,23 @@ fgetwc(FILE *fp)
36 * Non-MT-safe version.
37 */
38 wint_t
39 -__fgetwc(FILE *fp)
40 +__fgetwc(FILE *fp, locale_t loc)
41 {
42 wchar_t wc;
43 size_t nconv;
44 + struct __xlocale_st_runelocale *xrl = loc->__lc_ctype;
45 + size_t (*__mbrtowc)(wchar_t * __restrict, const char * __restrict, size_t, mbstate_t * __restrict, locale_t) = xrl->__mbrtowc;
46
47 if (fp->_r <= 0 && __srefill(fp))
48 return (WEOF);
49 - if (MB_CUR_MAX == 1) {
50 + if (xrl->__mb_cur_max == 1) {
51 /* Fast path for single-byte encodings. */
52 wc = *fp->_p++;
53 fp->_r--;
54 return (wc);
55 }
56 do {
57 - nconv = __mbrtowc(&wc, fp->_p, fp->_r, &fp->_mbstate);
58 + nconv = __mbrtowc(&wc, fp->_p, fp->_r, &fp->_mbstate, loc);
59 if (nconv == (size_t)-1)
60 break;
61 else if (nconv == (size_t)-2)