]> git.saurik.com Git - apple/libc.git/blame_incremental - stdio/FreeBSD/fgetws.c.patch
Libc-391.tar.gz
[apple/libc.git] / stdio / FreeBSD / fgetws.c.patch
... / ...
CommitLineData
1--- fgetws.c.orig 2004-11-25 11:38:34.000000000 -0800
2+++ fgetws.c 2005-02-24 16:20:29.000000000 -0800
3@@ -27,6 +27,8 @@
4 #include <sys/cdefs.h>
5 __FBSDID("$FreeBSD: src/lib/libc/stdio/fgetws.c,v 1.6 2004/10/03 15:48:32 stefanf Exp $");
6
7+#include "xlocale_private.h"
8+
9 #include "namespace.h"
10 #include <errno.h>
11 #include <stdio.h>
12@@ -38,13 +40,18 @@
13 #include "mblocal.h"
14
15 wchar_t *
16-fgetws(wchar_t * __restrict ws, int n, FILE * __restrict fp)
17+fgetws_l(wchar_t * __restrict ws, int n, FILE * __restrict fp, locale_t loc)
18 {
19 wchar_t *wsp;
20 size_t nconv;
21 const char *src;
22 unsigned char *nl;
23+ struct __xlocale_st_runelocale *rl;
24+ size_t (*__mbsnrtowcs)(wchar_t * __restrict, const char ** __restrict, size_t, size_t, __darwin_mbstate_t * __restrict, locale_t);
25
26+ NORMALIZE_LOCALE(loc);
27+ rl = loc->__lc_ctype;
28+ __mbsnrtowcs = rl->__mbsnrtowcs;
29 FLOCKFILE(fp);
30 ORIENT(fp, 1);
31
32@@ -58,11 +65,11 @@
33 goto error;
34 wsp = ws;
35 do {
36- src = fp->_p;
37+ src = (const char *)fp->_p;
38 nl = memchr(fp->_p, '\n', fp->_r);
39 nconv = __mbsnrtowcs(wsp, &src,
40 nl != NULL ? (nl - fp->_p + 1) : fp->_r,
41- n - 1, &fp->_extra->mbstate);
42+ n - 1, &fp->_extra->mbstate, loc);
43 if (nconv == (size_t)-1)
44 /* Conversion error */
45 goto error;
46@@ -86,7 +93,7 @@
47 if (wsp == ws)
48 /* EOF */
49 goto error;
50- if (!__mbsinit(&fp->_extra->mbstate))
51+ if (!rl->__mbsinit(&fp->_extra->mbstate, loc))
52 /* Incomplete character */
53 goto error;
54 *wsp++ = L'\0';
55@@ -98,3 +105,9 @@
56 FUNLOCKFILE(fp);
57 return (NULL);
58 }
59+
60+wchar_t *
61+fgetws(wchar_t * __restrict ws, int n, FILE * __restrict fp)
62+{
63+ return fgetws_l(ws, n, fp, __current_locale());
64+}