summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrey A. Chernov <ache@FreeBSD.org>2016-08-22 22:28:41 +0000
committerAndrey A. Chernov <ache@FreeBSD.org>2016-08-22 22:28:41 +0000
commitd34d90a89d0d34657f1de602abb861bba1a571d8 (patch)
treef06735bf348ed988b700e1e7b013f289162955e0
parent69afce5e645359ad9aad1ec20340bd7dc3aaf6f7 (diff)
Notes
-rw-r--r--lib/libc/stdio/fgetwc.c13
-rw-r--r--lib/libc/stdio/fgetwln.c18
2 files changed, 7 insertions, 24 deletions
diff --git a/lib/libc/stdio/fgetwc.c b/lib/libc/stdio/fgetwc.c
index 52bc988f7dc7..cf649fd841fe 100644
--- a/lib/libc/stdio/fgetwc.c
+++ b/lib/libc/stdio/fgetwc.c
@@ -79,18 +79,9 @@ __fgetwc_mbs(FILE *fp, mbstate_t *mbs, int *nread, locale_t locale)
size_t nconv;
struct xlocale_ctype *l = XLOCALE_CTYPE(locale);
- 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;
+ if (fp->_r <= 0 && __srefill(fp))
+ return (WEOF);
do {
nconv = l->__mbrtowc(&wc, fp->_p, fp->_r, mbs);
if (nconv == (size_t)-1)
diff --git a/lib/libc/stdio/fgetwln.c b/lib/libc/stdio/fgetwln.c
index 62a2f82e01be..6a92b71ce775 100644
--- a/lib/libc/stdio/fgetwln.c
+++ b/lib/libc/stdio/fgetwln.c
@@ -33,7 +33,6 @@
__FBSDID("$FreeBSD$");
#include "namespace.h"
-#include <errno.h>
#include <stdio.h>
#include <wchar.h>
#include "un-namespace.h"
@@ -48,39 +47,32 @@ fgetwln_l(FILE * __restrict fp, size_t *lenp, locale_t locale)
{
wint_t wc;
size_t len;
- int saverrno;
FIX_LOCALE(locale);
FLOCKFILE(fp);
ORIENT(fp, 1);
len = 0;
- saverrno = errno;
- errno = 0;
+ /* WEOF or error: return partial line, see fgetln(3). */
while ((wc = __fgetwc(fp, locale)) != WEOF) {
#define GROW 512
if (len * sizeof(wchar_t) >= fp->_lb._size &&
- __slbexpand(fp, (len + GROW) * sizeof(wchar_t)))
+ __slbexpand(fp, (len + GROW) * sizeof(wchar_t))) {
+ fp->_flags |= __SERR;
goto error;
+ }
*((wchar_t *)fp->_lb._base + len++) = wc;
if (wc == L'\n')
break;
- errno = 0;
}
- if (wc == WEOF && errno != 0)
- goto error;
- if (errno == 0)
- errno = saverrno;
if (len == 0)
- goto eof;
+ goto error;
FUNLOCKFILE(fp);
*lenp = len;
return ((wchar_t *)fp->_lb._base);
error:
- fp->_flags |= __SERR;
-eof:
FUNLOCKFILE(fp);
*lenp = 0;
return (NULL);