From owner-svn-src-stable-10@freebsd.org Thu Nov 19 02:04:17 2015 Return-Path: Delivered-To: svn-src-stable-10@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 DAF38A2FF96; Thu, 19 Nov 2015 02:04:17 +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 884311ED0; Thu, 19 Nov 2015 02:04:17 +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 tAJ24G9d053358; Thu, 19 Nov 2015 02:04:16 GMT (envelope-from ache@FreeBSD.org) Received: (from ache@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id tAJ24GXF053357; Thu, 19 Nov 2015 02:04:16 GMT (envelope-from ache@FreeBSD.org) Message-Id: <201511190204.tAJ24GXF053357@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ache set sender to ache@FreeBSD.org using -f From: "Andrey A. Chernov" Date: Thu, 19 Nov 2015 02:04:16 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r291050 - stable/10/lib/libc/stdio X-SVN-Group: stable-10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-10@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: SVN commit messages for only the 10-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 19 Nov 2015 02:04:18 -0000 Author: ache Date: Thu Nov 19 02:04:16 2015 New Revision: 291050 URL: https://svnweb.freebsd.org/changeset/base/291050 Log: MFC: r290549,r290729 r290549: Reorganize code to elimitate one _sseek() call for append modes. r290729: 1) Remove my overcomplicated error fallback and just return error immediatelly as old code does, now for append modes too. Real use case for such fallback is impossible (unless specially crafted). 2) Remove now unneded include I forgot to remove in prev. commits. Modified: stable/10/lib/libc/stdio/ftell.c Directory Properties: stable/10/ (props changed) Modified: stable/10/lib/libc/stdio/ftell.c ============================================================================== --- stable/10/lib/libc/stdio/ftell.c Thu Nov 19 01:58:12 2015 (r291049) +++ stable/10/lib/libc/stdio/ftell.c Thu Nov 19 02:04:16 2015 (r291050) @@ -39,7 +39,6 @@ __FBSDID("$FreeBSD$"); #include "namespace.h" #include #include -#include #include #include #include "un-namespace.h" @@ -98,7 +97,13 @@ _ftello(FILE *fp, fpos_t *offset) * Find offset of underlying I/O object, then * adjust for buffered bytes. */ - if (fp->_flags & __SOFF) + if (!(fp->_flags & __SRD) && (fp->_flags & __SWR) && + fp->_p != NULL && fp->_p - fp->_bf._base > 0 && + ((fp->_flags & __SAPP) || (fp->_flags2 & __S2OAP))) { + pos = _sseek(fp, (fpos_t)0, SEEK_END); + if (pos == -1) + return (1); + } else if (fp->_flags & __SOFF) pos = fp->_offset; else { pos = _sseek(fp, (fpos_t)0, SEEK_CUR); @@ -125,26 +130,6 @@ _ftello(FILE *fp, fpos_t *offset) * position to be greater than that in the * underlying object. */ - if ((fp->_flags & __SAPP) || (fp->_flags2 & __S2OAP)) { - int serrno = errno; - - errno = 0; - if ((pos = _sseek(fp, (fpos_t)0, SEEK_END)) == -1) { - if (errno == ESPIPE || - (fp->_flags & __SOPT) || __sflush(fp) || - (pos = - _sseek(fp, (fpos_t)0, SEEK_CUR)) == -1) - return (1); - else { - errno = serrno; - *offset = pos; - return (0); - } - } - errno = serrno; - /* fp->_p can be changed in _sseek(), recalculate. */ - n = fp->_p - fp->_bf._base; - } if (pos > OFF_MAX - n) { errno = EOVERFLOW; return (1);