From owner-svn-src-head@freebsd.org Wed Oct 28 14:40:04 2015 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 16615A201C2; Wed, 28 Oct 2015 14:40:04 +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 CCBEF1034; Wed, 28 Oct 2015 14:40:03 +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 t9SEe27A093924; Wed, 28 Oct 2015 14:40:02 GMT (envelope-from ache@FreeBSD.org) Received: (from ache@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id t9SEe2PR093917; Wed, 28 Oct 2015 14:40:02 GMT (envelope-from ache@FreeBSD.org) Message-Id: <201510281440.t9SEe2PR093917@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ache set sender to ache@FreeBSD.org using -f From: "Andrey A. Chernov" Date: Wed, 28 Oct 2015 14:40:02 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r290110 - in head: include 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.20 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: Wed, 28 Oct 2015 14:40:04 -0000 Author: ache Date: Wed Oct 28 14:40:02 2015 New Revision: 290110 URL: https://svnweb.freebsd.org/changeset/base/290110 Log: Add _flags2 per jhb@ suggestion since no room left in _flags. Rewrite O_APPEND flag checking using new __S2OAP flag. MFC after: 3 weeks Modified: head/include/stdio.h head/lib/libc/stdio/fdopen.c head/lib/libc/stdio/findfp.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/include/stdio.h ============================================================================== --- head/include/stdio.h Wed Oct 28 14:21:53 2015 (r290109) +++ head/include/stdio.h Wed Oct 28 14:40:02 2015 (r290110) @@ -144,6 +144,7 @@ struct __sFILE { int _fl_count; /* recursive lock count */ int _orientation; /* orientation for fwide() */ __mbstate_t _mbstate; /* multibyte conversion state */ + int _flags2; /* additional flags */ }; #ifndef _STDFILE_DECLARED #define _STDFILE_DECLARED @@ -176,6 +177,8 @@ __END_DECLS #define __SALC 0x4000 /* allocate string space dynamically */ #define __SIGN 0x8000 /* ignore this file in _fwalk */ +#define __S2OAP 0x0001 /* O_APPEND mode is set */ + /* * The following three definitions are for ANSI C, which took them * from System V, which brilliantly took internal interface macros and Modified: head/lib/libc/stdio/fdopen.c ============================================================================== --- head/lib/libc/stdio/fdopen.c Wed Oct 28 14:21:53 2015 (r290109) +++ head/lib/libc/stdio/fdopen.c Wed Oct 28 14:40:02 2015 (r290110) @@ -91,9 +91,8 @@ fdopen(int fd, const char *mode) * O_APPEND bit set, assert __SAPP so that __swrite() caller * will _sseek() to the end before write. */ - /* XXX: Reuse __SALC for O_APPEND. */ if (fdflags & O_APPEND) - fp->_flags |= __SALC; + fp->_flags2 |= __S2OAP; else if (oflags & O_APPEND) fp->_flags |= __SAPP; fp->_file = fd; Modified: head/lib/libc/stdio/findfp.c ============================================================================== --- head/lib/libc/stdio/findfp.c Wed Oct 28 14:21:53 2015 (r290109) +++ head/lib/libc/stdio/findfp.c Wed Oct 28 14:40:02 2015 (r290110) @@ -155,6 +155,7 @@ found: /* fp->_fl_mutex = NULL; */ /* once set always set (reused) */ fp->_orientation = 0; memset(&fp->_mbstate, 0, sizeof(mbstate_t)); + fp->_flags2 = 0; return (fp); } Modified: head/lib/libc/stdio/fopen.c ============================================================================== --- head/lib/libc/stdio/fopen.c Wed Oct 28 14:21:53 2015 (r290109) +++ head/lib/libc/stdio/fopen.c Wed Oct 28 14:40:02 2015 (r290110) @@ -92,8 +92,7 @@ fopen(const char * __restrict file, cons * fseek and ftell.) */ if (oflags & O_APPEND) { - /* XXX: Reuse __SALC for O_APPEND. */ - fp->_flags |= __SALC; + fp->_flags2 |= __S2OAP; (void)_sseek(fp, (fpos_t)0, SEEK_END); } return (fp); Modified: head/lib/libc/stdio/freopen.c ============================================================================== --- head/lib/libc/stdio/freopen.c Wed Oct 28 14:21:53 2015 (r290109) +++ head/lib/libc/stdio/freopen.c Wed Oct 28 14:40:02 2015 (r290110) @@ -187,6 +187,7 @@ finish: fp->_lb._size = 0; fp->_orientation = 0; memset(&fp->_mbstate, 0, sizeof(mbstate_t)); + fp->_flags2 = 0; if (f < 0) { /* did not get it after all */ if (isopen) @@ -241,8 +242,7 @@ finish: * fseek and ftell.) */ if (oflags & O_APPEND) { - /* XXX: Reuse __SALC for O_APPEND. */ - fp->_flags |= __SALC; + fp->_flags2 |= __S2OAP; (void) _sseek(fp, (fpos_t)0, SEEK_END); } FUNLOCKFILE(fp); Modified: head/lib/libc/stdio/ftell.c ============================================================================== --- head/lib/libc/stdio/ftell.c Wed Oct 28 14:21:53 2015 (r290109) +++ head/lib/libc/stdio/ftell.c Wed Oct 28 14:40:02 2015 (r290110) @@ -119,8 +119,7 @@ _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) { - /* XXX: Reuse __SALC for O_APPEND. */ - if (fp->_flags & (__SAPP|__SALC)) { + if ((fp->_flags & __SAPP) || (fp->_flags2 & __S2OAP)) { int serrno = errno; errno = 0; Modified: head/lib/libc/stdio/stdio.c ============================================================================== --- head/lib/libc/stdio/stdio.c Wed Oct 28 14:21:53 2015 (r290109) +++ head/lib/libc/stdio/stdio.c Wed Oct 28 14:40:02 2015 (r290110) @@ -117,8 +117,7 @@ _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) { - /* XXX: Reuse __SALC for O_APPEND. */ - if ((fp->_flags & __SOFF) && !(fp->_flags & __SALC) && + if ((fp->_flags & __SOFF) && !(fp->_flags2 & __S2OAP) && fp->_offset <= OFF_MAX - ret) fp->_offset += ret; else