4
0
mirror of git://sourceware.org/git/newlib-cygwin.git synced 2025-02-18 23:12:15 +08:00

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.
This commit is contained in:
Eric Blake 2007-07-31 20:49:40 +00:00
parent 8b5fa210a6
commit f7c978d50f
4 changed files with 30 additions and 23 deletions

View File

@ -1,3 +1,11 @@
2007-07-31 Eric Blake <ebb9@byu.net>
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.
2007-07-18 Eric Blake <ebb9@byu.net> 2007-07-18 Eric Blake <ebb9@byu.net>
Fix 'make info'. Fix 'make info'.

View File

@ -29,7 +29,7 @@ ANSI_SYNOPSIS
FILE *fdopen(int <[fd]>, const char *<[mode]>); FILE *fdopen(int <[fd]>, const char *<[mode]>);
FILE *_fdopen_r(struct _reent *<[reent]>, FILE *_fdopen_r(struct _reent *<[reent]>,
int <[fd]>, const char *<[mode]>); int <[fd]>, const char *<[mode]>);
TRAD_SYNOPSIS TRAD_SYNOPSIS
#include <stdio.h> #include <stdio.h>
FILE *fdopen(<[fd]>, <[mode]>) FILE *fdopen(<[fd]>, <[mode]>)
@ -96,17 +96,14 @@ _DEFUN(_fdopen_r, (ptr, fd, mode),
_flockfile (fp); _flockfile (fp);
fp->_flags = flags; fp->_flags = flags;
/* /* POSIX recommends setting the O_APPEND bit on fd to match append
* If opened for appending, but underlying descriptor streams. Someone may later clear O_APPEND on fileno(fp), but the
* does not have O_APPEND bit set, assert __SAPP so that stream must still remain in append mode. Rely on __sflags
* __swrite() will lseek to end before each write. setting __SAPP properly. */
*/
if ((oflags & O_APPEND)
#ifdef HAVE_FCNTL #ifdef HAVE_FCNTL
&& !(fdflags & O_APPEND) if ((oflags & O_APPEND) && !(fdflags & O_APPEND))
_fcntl_r (ptr, fd, F_SETFL, fdflags | O_APPEND);
#endif #endif
)
fp->_flags |= __SAPP;
fp->_file = fd; fp->_file = fd;
fp->_cookie = (_PTR) fp; fp->_cookie = (_PTR) fp;

View File

@ -204,16 +204,21 @@ _DEFUN(__sinit, (s),
std (s->_stdin, __SRD, 0, s); std (s->_stdin, __SRD, 0, s);
/* on platforms that have true file system I/O, we can verify whether stdout /* On platforms that have true file system I/O, we can verify
is an interactive terminal or not. For all other platforms, we will whether stdout is an interactive terminal or not, as part of
default to line buffered mode here. */ __smakebuf on first use of the stream. For all other platforms,
we will default to line buffered mode here. Technically, POSIX
requires both stdin and stdout to be line-buffered, but tradition
leaves stdin alone on systems without fcntl. */
#ifdef HAVE_FCNTL #ifdef HAVE_FCNTL
std (s->_stdout, __SWR, 1, s); std (s->_stdout, __SWR, 1, s);
#else #else
std (s->_stdout, __SWR | __SLBF, 1, s); std (s->_stdout, __SWR | __SLBF, 1, s);
#endif #endif
std (s->_stderr, __SWR | __SNBF, 2, s); /* POSIX requires stderr to be opened for reading and writing, even
when the underlying fd 2 is write-only. */
std (s->_stderr, __SRW | __SNBF, 2, s);
__sinit_lock_release (); __sinit_lock_release ();
} }

View File

@ -67,17 +67,14 @@ _DEFUN (_fdopen64_r, (ptr, fd, mode),
_flockfile(fp); _flockfile(fp);
fp->_flags = flags; fp->_flags = flags;
/* /* POSIX recommends setting the O_APPEND bit on fd to match append
* If opened for appending, but underlying descriptor streams. Someone may later clear O_APPEND on fileno(fp), but the
* does not have O_APPEND bit set, assert __SAPP so that stream must still remain in append mode. Rely on __sflags
* __swrite() will lseek to end before each write. setting __SAPP properly. */
*/
if ((oflags & O_APPEND)
#ifdef HAVE_FCNTL #ifdef HAVE_FCNTL
&& !(fdflags & O_APPEND) if ((oflags & O_APPEND) && !(fdflags & O_APPEND))
_fcntl_r (ptr, fd, F_SETFL, fdflags | O_APPEND);
#endif #endif
)
fp->_flags |= __SAPP;
fp->_file = fd; fp->_file = fd;
fp->_cookie = (_PTR) fp; fp->_cookie = (_PTR) fp;