Date: Sun, 1 Nov 2015 06:15:14 +0000 (UTC) From: "Andrey A. Chernov" <ache@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r290230 - head/lib/libc/stdio Message-ID: <201511010615.tA16FELV071017@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: ache Date: Sun Nov 1 06:15:14 2015 New Revision: 290230 URL: https://svnweb.freebsd.org/changeset/base/290230 Log: Don't seek to the end if write buffer is empty (in append modes). PR: 204156 MFC after: 1 week Modified: head/lib/libc/stdio/ftell.c Modified: head/lib/libc/stdio/ftell.c ============================================================================== --- head/lib/libc/stdio/ftell.c Sat Oct 31 20:38:06 2015 (r290229) +++ head/lib/libc/stdio/ftell.c Sun Nov 1 06:15:14 2015 (r290230) @@ -119,7 +119,18 @@ _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) { - if ((fp->_flags & __SAPP) || (fp->_flags2 & __S2OAP)) { + /* + * Writing. Any buffered characters cause the + * position to be greater than that in the + * underlying object. + */ + n = fp->_p - fp->_bf._base; + if (pos > OFF_MAX - n) { + errno = EOVERFLOW; + return (1); + } + if (n > 0 && + ((fp->_flags & __SAPP) || (fp->_flags2 & __S2OAP))) { int serrno = errno; errno = 0; @@ -137,16 +148,6 @@ _ftello(FILE *fp, fpos_t *offset) } errno = serrno; } - /* - * Writing. Any buffered characters cause the - * position to be greater than that in the - * underlying object. - */ - n = fp->_p - fp->_bf._base; - if (pos > OFF_MAX - n) { - errno = EOVERFLOW; - return (1); - } pos += n; } *offset = pos;
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201511010615.tA16FELV071017>