From f7c978d50fb7f510864ff4770fa7793a47a0b613 Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Tue, 31 Jul 2007 20:49:40 +0000 Subject: More POSIX stream corner cases. * libc/stdio/findfp.c (__sinit): Open stderr read/write. * libc/stdio/fdopen.c (_fdopen_r): Set O_APPEND on fd when requested. * libc/stdio64/fdopen64.c (_fdopen64_r): Likewise. --- newlib/libc/stdio64/fdopen64.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) (limited to 'newlib/libc/stdio64/fdopen64.c') diff --git a/newlib/libc/stdio64/fdopen64.c b/newlib/libc/stdio64/fdopen64.c index 4f159e813..49d1f03aa 100644 --- a/newlib/libc/stdio64/fdopen64.c +++ b/newlib/libc/stdio64/fdopen64.c @@ -67,17 +67,14 @@ _DEFUN (_fdopen64_r, (ptr, fd, mode), _flockfile(fp); fp->_flags = flags; - /* - * If opened for appending, but underlying descriptor - * does not have O_APPEND bit set, assert __SAPP so that - * __swrite() will lseek to end before each write. - */ - if ((oflags & O_APPEND) + /* POSIX recommends setting the O_APPEND bit on fd to match append + streams. Someone may later clear O_APPEND on fileno(fp), but the + stream must still remain in append mode. Rely on __sflags + setting __SAPP properly. */ #ifdef HAVE_FCNTL - && !(fdflags & O_APPEND) + if ((oflags & O_APPEND) && !(fdflags & O_APPEND)) + _fcntl_r (ptr, fd, F_SETFL, fdflags | O_APPEND); #endif - ) - fp->_flags |= __SAPP; fp->_file = fd; fp->_cookie = (_PTR) fp; -- cgit v1.2.3