1
0
mirror of https://git.FreeBSD.org/src.git synced 2024-10-20 02:38:43 +00:00

fgetwc(3) may set both __SEOF and __SERR at once (in case of incomplete

sequence near EOF), so we can't just check for
(wc == WEOF && !__sfeof(fp)) and must relay on __sferror(fp) with
__SERR clearing/restoring.

MFC after:      7 days
This commit is contained in:
Andrey A. Chernov 2016-09-01 20:45:04 +00:00
parent 7cba15b16e
commit 2fbab0097a
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=305241

View File

@ -47,11 +47,16 @@ fgetwln_l(FILE * __restrict fp, size_t *lenp, locale_t locale)
{
wint_t wc;
size_t len;
int savserr;
FIX_LOCALE(locale);
FLOCKFILE(fp);
ORIENT(fp, 1);
savserr = fp->_flags & __SERR;
fp->_flags &= ~__SERR;
len = 0;
while ((wc = __fgetwc(fp, locale)) != WEOF) {
#define GROW 512
@ -64,7 +69,12 @@ fgetwln_l(FILE * __restrict fp, size_t *lenp, locale_t locale)
if (wc == L'\n')
break;
}
if (len == 0 || (wc == WEOF && !__sfeof(fp)))
/* fgetwc(3) may set both __SEOF and __SERR at once. */
if (__sferror(fp))
goto error;
fp->_flags |= savserr;
if (len == 0)
goto error;
FUNLOCKFILE(fp);