*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/stdio/fgetws.c,v 1.6 2004/10/03 15:48:32 stefanf Exp $");
+__FBSDID("$FreeBSD: src/lib/libc/stdio/fgetws.c,v 1.8 2009/11/25 04:45:45 wollman Exp $");
+
+#include "xlocale_private.h"
#include "namespace.h"
#include <errno.h>
#include "mblocal.h"
wchar_t *
-fgetws(wchar_t * __restrict ws, int n, FILE * __restrict fp)
+fgetws_l(wchar_t * __restrict ws, int n, FILE * __restrict fp, locale_t loc)
{
wchar_t *wsp;
size_t nconv;
const char *src;
unsigned char *nl;
+ struct __xlocale_st_runelocale *rl;
+ size_t (*__mbsnrtowcs)(wchar_t * __restrict, const char ** __restrict, size_t, size_t, __darwin_mbstate_t * __restrict, locale_t);
+ NORMALIZE_LOCALE(loc);
+ rl = loc->__lc_ctype;
+ __mbsnrtowcs = rl->__mbsnrtowcs;
FLOCKFILE(fp);
ORIENT(fp, 1);
goto error;
wsp = ws;
do {
- src = fp->_p;
+ src = (const char *)fp->_p;
nl = memchr(fp->_p, '\n', fp->_r);
nconv = __mbsnrtowcs(wsp, &src,
nl != NULL ? (nl - fp->_p + 1) : fp->_r,
- n - 1, &fp->_extra->mbstate);
+ n - 1, &fp->_mbstate, loc);
if (nconv == (size_t)-1)
/* Conversion error */
goto error;
if (wsp == ws)
/* EOF */
goto error;
- if (!__mbsinit(&fp->_extra->mbstate))
+ if (!rl->__mbsinit(&fp->_mbstate, loc))
/* Incomplete character */
goto error;
- *wsp++ = L'\0';
+ *wsp = L'\0';
FUNLOCKFILE(fp);
return (ws);
FUNLOCKFILE(fp);
return (NULL);
}
+
+wchar_t *
+fgetws(wchar_t * __restrict ws, int n, FILE * __restrict fp)
+{
+ return fgetws_l(ws, n, fp, __current_locale());
+}