From owner-svn-src-head@freebsd.org Mon Aug 22 22:28:42 2016 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id DD164BC2D4A; Mon, 22 Aug 2016 22:28:42 +0000 (UTC) (envelope-from ache@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 8F8ED14E7; Mon, 22 Aug 2016 22:28:42 +0000 (UTC) (envelope-from ache@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u7MMSfvV046609; Mon, 22 Aug 2016 22:28:41 GMT (envelope-from ache@FreeBSD.org) Received: (from ache@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u7MMSfkx046607; Mon, 22 Aug 2016 22:28:41 GMT (envelope-from ache@FreeBSD.org) Message-Id: <201608222228.u7MMSfkx046607@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ache set sender to ache@FreeBSD.org using -f From: "Andrey A. Chernov" Date: Mon, 22 Aug 2016 22:28:41 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r304641 - head/lib/libc/stdio X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 22 Aug 2016 22:28:43 -0000 Author: ache Date: Mon Aug 22 22:28:41 2016 New Revision: 304641 URL: https://svnweb.freebsd.org/changeset/base/304641 Log: 1) Back out r304607 case 2). fgetwln() as its pair fgetln() supposed to return partial line on any errors. See the comment in fgetln.c. Add corresponding comment to fgetwln() too. 2) Rewrite r304607 case 1). 3) Remove "Fast path" from __fgetwc_mbs() since it can't detect encoding errors and ignores them all. PR: 212033 MFC after: 7 days Modified: head/lib/libc/stdio/fgetwc.c head/lib/libc/stdio/fgetwln.c Modified: head/lib/libc/stdio/fgetwc.c ============================================================================== --- head/lib/libc/stdio/fgetwc.c Mon Aug 22 21:49:17 2016 (r304640) +++ head/lib/libc/stdio/fgetwc.c Mon Aug 22 22:28:41 2016 (r304641) @@ -79,18 +79,9 @@ __fgetwc_mbs(FILE *fp, mbstate_t *mbs, i 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) Modified: head/lib/libc/stdio/fgetwln.c ============================================================================== --- head/lib/libc/stdio/fgetwln.c Mon Aug 22 21:49:17 2016 (r304640) +++ head/lib/libc/stdio/fgetwln.c Mon Aug 22 22:28:41 2016 (r304641) @@ -33,7 +33,6 @@ __FBSDID("$FreeBSD$"); #include "namespace.h" -#include #include #include #include "un-namespace.h" @@ -48,39 +47,32 @@ fgetwln_l(FILE * __restrict fp, size_t * { 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);