summaryrefslogtreecommitdiffstats
path: root/lib/libc/stdio/fgetwc.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libc/stdio/fgetwc.c')
-rw-r--r--lib/libc/stdio/fgetwc.c24
1 files changed, 15 insertions, 9 deletions
diff --git a/lib/libc/stdio/fgetwc.c b/lib/libc/stdio/fgetwc.c
index 0e87753..52bc988 100644
--- a/lib/libc/stdio/fgetwc.c
+++ b/lib/libc/stdio/fgetwc.c
@@ -59,6 +59,7 @@ fgetwc_l(FILE *fp, locale_t locale)
return (r);
}
+
wint_t
fgetwc(FILE *fp)
{
@@ -66,40 +67,45 @@ fgetwc(FILE *fp)
}
/*
- * Non-MT-safe version.
+ * Internal (non-MPSAFE) version of fgetwc(). This version takes an
+ * mbstate_t argument specifying the initial conversion state. For
+ * wide streams, this should always be fp->_mbstate. On return, *nread
+ * is set to the number of bytes read.
*/
-wint_t
-__fgetwc(FILE *fp, locale_t locale)
+wint_t
+__fgetwc_mbs(FILE *fp, mbstate_t *mbs, int *nread, locale_t locale)
{
wchar_t wc;
size_t nconv;
struct xlocale_ctype *l = XLOCALE_CTYPE(locale);
- if (fp->_r <= 0 && __srefill(fp))
+ if (fp->_r <= 0 && __srefill(fp)) {
+ *nread = 0;
return (WEOF);
+ }
if (MB_CUR_MAX == 1) {
/* Fast path for single-byte encodings. */
wc = *fp->_p++;
fp->_r--;
+ *nread = 1;
return (wc);
}
+ *nread = 0;
do {
- nconv = l->__mbrtowc(&wc, fp->_p, fp->_r, &fp->_mbstate);
+ nconv = l->__mbrtowc(&wc, fp->_p, fp->_r, mbs);
if (nconv == (size_t)-1)
break;
else if (nconv == (size_t)-2)
continue;
else if (nconv == 0) {
- /*
- * Assume that the only valid representation of
- * the null wide character is a single null byte.
- */
fp->_p++;
fp->_r--;
+ (*nread)++;
return (L'\0');
} else {
fp->_p += nconv;
fp->_r -= nconv;
+ *nread += nconv;
return (wc);
}
} while (__srefill(fp) == 0);
OpenPOWER on IntegriCloud