]> git.saurik.com Git - apple/libc.git/blame - stdio/FreeBSD/fgetwc.c.patch
Libc-391.2.3.tar.gz
[apple/libc.git] / stdio / FreeBSD / fgetwc.c.patch
CommitLineData
3d9156a7
A
1--- fgetwc.c.orig 2004-11-25 11:38:34.000000000 -0800
2+++ fgetwc.c 2005-02-23 17:15:00.000000000 -0800
3@@ -27,6 +27,8 @@
4 #include <sys/cdefs.h>
5 __FBSDID("$FreeBSD: src/lib/libc/stdio/fgetwc.c,v 1.12 2004/07/20 08:27:27 tjr 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 @@
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 @@
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->_extra->mbstate);
58+ nconv = __mbrtowc(&wc, fp->_p, fp->_r, &fp->_extra->mbstate, loc);
59 if (nconv == (size_t)-1)
60 break;
61 else if (nconv == (size_t)-2)