diff options
author | 2016-08-27 12:08:38 +0000 | |
---|---|---|
committer | 2016-08-27 12:08:38 +0000 | |
commit | 1c50512a2b2262363e327edc19370b2d0339ca11 (patch) | |
tree | 35c487f6c5371d7739612f359339cdae64222166 /lib/libc/stdio | |
parent | Add support for sun8i-h3, the Allwinner H3. For this SoC, the device tree (diff) | |
download | wireguard-openbsd-1c50512a2b2262363e327edc19370b2d0339ca11.tar.xz wireguard-openbsd-1c50512a2b2262363e327edc19370b2d0339ca11.zip |
improve revision 1.2: in unusual cases, fgetwc(3) can succeed
even though ferror(3) is already set;
also from Andrey Chernov <ache at freebsd dot org>;
OK millert@
Diffstat (limited to 'lib/libc/stdio')
-rw-r--r-- | lib/libc/stdio/fgetwln.c | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/lib/libc/stdio/fgetwln.c b/lib/libc/stdio/fgetwln.c index 2ee7e8d61e6..aba11b5b285 100644 --- a/lib/libc/stdio/fgetwln.c +++ b/lib/libc/stdio/fgetwln.c @@ -1,4 +1,4 @@ -/* $OpenBSD: fgetwln.c,v 1.3 2016/08/24 18:35:12 schwarze Exp $ */ +/* $OpenBSD: fgetwln.c,v 1.4 2016/08/27 12:08:38 schwarze Exp $ */ /*- * Copyright (c) 2002-2004 Tim J. Robbins. @@ -69,7 +69,17 @@ fgetwln(FILE * __restrict fp, size_t *lenp) if (wc == L'\n') break; } - if (len == 0 || fp->_flags & __SERR) + + /* + * The following test assumes that fgetwc() fails when + * feof() is already set, and that fgetwc() will never + * set feof() in the same call where it also sets ferror() + * or returns non-WEOF. + * Testing ferror() would not be better because fgetwc() + * may succeed even when ferror() is already set. + */ + + if (len == 0 || (wc == WEOF && !__sfeof(fp))) goto error; FUNLOCKFILE(fp); |