diff options
author | ache <ache@FreeBSD.org> | 2015-11-08 13:37:16 +0000 |
---|---|---|
committer | ache <ache@FreeBSD.org> | 2015-11-08 13:37:16 +0000 |
commit | 8a3e4a6db71e690b2b8bf5f3372f4f99a506fdd7 (patch) | |
tree | 20f498bd623fab85c76c978a69e059c9bda125d0 /lib/libc/stdio/freopen.c | |
parent | 1df83ba3d3bc30d9297c344788b7ce3dbe3eb69b (diff) | |
download | FreeBSD-src-8a3e4a6db71e690b2b8bf5f3372f4f99a506fdd7.zip FreeBSD-src-8a3e4a6db71e690b2b8bf5f3372f4f99a506fdd7.tar.gz |
MFC: r289863,r289931,r290110,r290230,r290231,r290232
r290232:
Microoptimize.
r290231:
Addition to prev. commit.
In some edge cases fp->_p can be changed in _sseek(), recalculate.
r290230:
Don't seek to the end if write buffer is empty (in append modes).
PR: 204156
r290110:
Add _flags2 per jhb@ suggestion since no room left in _flags.
Rewrite O_APPEND flag checking using new __S2OAP flag.
r289931:
According to POSIX, a write operation shall start at the current size of
the stream (if mode had 'a' as the first character).
r289863:
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().
Diffstat (limited to 'lib/libc/stdio/freopen.c')
-rw-r--r-- | lib/libc/stdio/freopen.c | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/lib/libc/stdio/freopen.c b/lib/libc/stdio/freopen.c index bf3f030..58227fa 100644 --- a/lib/libc/stdio/freopen.c +++ b/lib/libc/stdio/freopen.c @@ -186,6 +186,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) @@ -239,8 +240,10 @@ finish: * we can do about this. (We could set __SAPP and check in * fseek and ftell.) */ - if (oflags & O_APPEND) + if (oflags & O_APPEND) { + fp->_flags2 |= __S2OAP; (void) _sseek(fp, (fpos_t)0, SEEK_END); + } FUNLOCKFILE(fp); return (fp); } |