]>
Commit | Line | Data |
---|---|---|
1f2f436a A |
1 | --- fgetws.c.bsdnew 2009-11-30 16:15:32.000000000 -0800 |
2 | +++ fgetws.c 2009-11-30 16:15:32.000000000 -0800 | |
3d9156a7 A |
3 | @@ -27,6 +27,8 @@ |
4 | #include <sys/cdefs.h> | |
1f2f436a | 5 | __FBSDID("$FreeBSD: src/lib/libc/stdio/fgetws.c,v 1.8 2009/11/25 04:45:45 wollman Exp $"); |
3d9156a7 A |
6 | |
7 | +#include "xlocale_private.h" | |
8 | + | |
9 | #include "namespace.h" | |
10 | #include <errno.h> | |
11 | #include <stdio.h> | |
1f2f436a | 12 | @@ -38,13 +40,18 @@ __FBSDID("$FreeBSD: src/lib/libc/stdio/f |
3d9156a7 A |
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 | ||
1f2f436a | 32 | @@ -58,11 +65,11 @@ fgetws(wchar_t * __restrict ws, int n, F |
3d9156a7 A |
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, | |
1f2f436a A |
41 | - n - 1, &fp->_mbstate); |
42 | + n - 1, &fp->_mbstate, loc); | |
3d9156a7 A |
43 | if (nconv == (size_t)-1) |
44 | /* Conversion error */ | |
45 | goto error; | |
1f2f436a | 46 | @@ -86,7 +93,7 @@ fgetws(wchar_t * __restrict ws, int n, F |
3d9156a7 A |
47 | if (wsp == ws) |
48 | /* EOF */ | |
49 | goto error; | |
1f2f436a A |
50 | - if (!__mbsinit(&fp->_mbstate)) |
51 | + if (!rl->__mbsinit(&fp->_mbstate, loc)) | |
3d9156a7 A |
52 | /* Incomplete character */ |
53 | goto error; | |
1f2f436a A |
54 | *wsp = L'\0'; |
55 | @@ -98,3 +105,9 @@ error: | |
3d9156a7 A |
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 | +} |