From owner-svn-src-all@freebsd.org Sat Oct 24 02:23:16 2015 Return-Path: Delivered-To: svn-src-all@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 C6CC0A1850A; Sat, 24 Oct 2015 02:23:16 +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 95CC31ED4; Sat, 24 Oct 2015 02:23:16 +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 t9O2NFM6011541; Sat, 24 Oct 2015 02:23:15 GMT (envelope-from ache@FreeBSD.org) Received: (from ache@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id t9O2NFiY011536; Sat, 24 Oct 2015 02:23:15 GMT (envelope-from ache@FreeBSD.org) Message-Id: <201510240223.t9O2NFiY011536@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ache set sender to ache@FreeBSD.org using -f From: "Andrey A. Chernov" Date: Sat, 24 Oct 2015 02:23:15 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r289863 - 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-all@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 24 Oct 2015 02:23:16 -0000 Author: ache Date: Sat Oct 24 02:23:15 2015 New Revision: 289863 URL: https://svnweb.freebsd.org/changeset/base/289863 Log: Since no room left in the _flags, reuse __SALC for O_APPEND. It helps to remove _fcntl() call from _ftello() and optimize seek position calculation in _swrite(). MFC after: 3 weeks Modified: head/lib/libc/stdio/fdopen.c head/lib/libc/stdio/fopen.c head/lib/libc/stdio/freopen.c head/lib/libc/stdio/ftell.c head/lib/libc/stdio/stdio.c Modified: head/lib/libc/stdio/fdopen.c ============================================================================== --- head/lib/libc/stdio/fdopen.c Sat Oct 24 02:18:14 2015 (r289862) +++ head/lib/libc/stdio/fdopen.c Sat Oct 24 02:23:15 2015 (r289863) @@ -91,7 +91,10 @@ fdopen(int fd, const char *mode) * O_APPEND bit set, assert __SAPP so that __swrite() caller * will _sseek() to the end before write. */ - if ((oflags & O_APPEND) && !(fdflags & O_APPEND)) + /* XXX: Reuse __SALC for O_APPEND. */ + if (fdflags & O_APPEND) + fp->_flags |= __SALC; + else if (oflags & O_APPEND) fp->_flags |= __SAPP; fp->_file = fd; fp->_cookie = fp; Modified: head/lib/libc/stdio/fopen.c ============================================================================== --- head/lib/libc/stdio/fopen.c Sat Oct 24 02:18:14 2015 (r289862) +++ head/lib/libc/stdio/fopen.c Sat Oct 24 02:23:15 2015 (r289863) @@ -91,7 +91,10 @@ fopen(const char * __restrict file, cons * we can do about this. (We could set __SAPP and check in * fseek and ftell.) */ - if (oflags & O_APPEND) + if (oflags & O_APPEND) { + /* XXX: Reuse __SALC for O_APPEND. */ + fp->_flags |= __SALC; (void)_sseek(fp, (fpos_t)0, SEEK_END); + } return (fp); } Modified: head/lib/libc/stdio/freopen.c ============================================================================== --- head/lib/libc/stdio/freopen.c Sat Oct 24 02:18:14 2015 (r289862) +++ head/lib/libc/stdio/freopen.c Sat Oct 24 02:23:15 2015 (r289863) @@ -240,8 +240,11 @@ finish: * we can do about this. (We could set __SAPP and check in * fseek and ftell.) */ - if (oflags & O_APPEND) + if (oflags & O_APPEND) { + /* XXX: Reuse __SALC for O_APPEND. */ + fp->_flags |= __SALC; (void) _sseek(fp, (fpos_t)0, SEEK_END); + } FUNLOCKFILE(fp); return (fp); } Modified: head/lib/libc/stdio/ftell.c ============================================================================== --- head/lib/libc/stdio/ftell.c Sat Oct 24 02:18:14 2015 (r289862) +++ head/lib/libc/stdio/ftell.c Sat Oct 24 02:23:15 2015 (r289863) @@ -88,7 +88,6 @@ _ftello(FILE *fp, fpos_t *offset) { fpos_t pos; size_t n; - int dflags; if (fp->_seek == NULL) { errno = ESPIPE; /* historic practice */ @@ -120,21 +119,24 @@ _ftello(FILE *fp, fpos_t *offset) if (HASUB(fp)) pos -= fp->_r; /* Can be negative at this point. */ } else if ((fp->_flags & __SWR) && fp->_p != NULL) { - dflags = 0; - if (fp->_flags & __SAPP) - dflags = O_APPEND; - else if (fp->_file != -1 && - (dflags = _fcntl(fp->_file, F_GETFL)) < 0) - return (1); - if ((dflags & O_APPEND) && - (pos = _sseek(fp, (fpos_t)0, SEEK_END)) == -1) { - if ((fp->_flags & __SOPT) || __sflush(fp) || - (pos = _sseek(fp, (fpos_t)0, SEEK_CUR)) == -1) - return (1); - else { - *offset = pos; - return (0); + /* XXX: Reuse __SALC for O_APPEND. */ + if (fp->_flags & (__SAPP|__SALC)) { + 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; } /* * Writing. Any buffered characters cause the Modified: head/lib/libc/stdio/stdio.c ============================================================================== --- head/lib/libc/stdio/stdio.c Sat Oct 24 02:18:14 2015 (r289862) +++ head/lib/libc/stdio/stdio.c Sat Oct 24 02:23:15 2015 (r289863) @@ -117,7 +117,8 @@ _swrite(FILE *fp, char const *buf, int n ret = (*fp->_write)(fp->_cookie, buf, n); /* __SOFF removed even on success in case O_APPEND mode is set. */ if (ret >= 0) { - if ((fp->_flags & (__SAPP|__SOFF)) == (__SAPP|__SOFF) && + /* XXX: Reuse __SALC for O_APPEND. */ + if ((fp->_flags & __SOFF) && !(fp->_flags & __SALC) && fp->_offset <= OFF_MAX - ret) fp->_offset += ret; else