diff options
author | Ulrich Drepper <drepper@gmail.com> | 2011-05-15 15:28:46 -0400 |
---|---|---|
committer | Ulrich Drepper <drepper@gmail.com> | 2011-05-15 15:28:46 -0400 |
commit | 94b7cc3711b0b74c1d3ae18b9a2e019e51a8e0bf (patch) | |
tree | 2ddc8ca200024ecca3faf0f2efffaea15e21a04f /libio/oldfileops.c | |
parent | bd25564e1e98910ed69043ed6a6f884ce60e5780 (diff) | |
download | glibc-94b7cc3711b0b74c1d3ae18b9a2e019e51a8e0bf.tar.gz glibc-94b7cc3711b0b74c1d3ae18b9a2e019e51a8e0bf.tar.xz glibc-94b7cc3711b0b74c1d3ae18b9a2e019e51a8e0bf.zip |
Fix a few problems in fopen and freopen
fopen should set the FD_CLOEXEC flag if requested evenif the kernel does not support an aotmic operation. freopen should reuse the file descriptor for the stream. This is especially important for calls to change the standard streams (stin, stdout, stderr).
Diffstat (limited to 'libio/oldfileops.c')
-rw-r--r-- | libio/oldfileops.c | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/libio/oldfileops.c b/libio/oldfileops.c index be99a2500c..3e3daa8ae1 100644 --- a/libio/oldfileops.c +++ b/libio/oldfileops.c @@ -155,7 +155,8 @@ _IO_old_file_close_it (fp) INTUSE(_IO_unsave_markers) (fp); - close_status = _IO_SYSCLOSE (fp); + close_status = ((fp->_flags2 & _IO_FLAGS2_NOCLOSE) == 0 + ? _IO_SYSCLOSE (fp) : 0); /* Free buffer. */ INTUSE(_IO_setb) (fp, NULL, NULL, 0); @@ -676,7 +677,7 @@ _IO_old_file_write (f, data, n) { f->_flags |= _IO_ERR_SEEN; break; - } + } to_do -= count; data = (void *) ((char *) data + count); } @@ -763,12 +764,12 @@ _IO_old_file_xsputn (f, data, n) do_write = to_do - (block_size >= 128 ? to_do % block_size : 0); if (do_write) - { + { count = old_do_write (f, s, do_write); to_do -= count; if (count < do_write) return n - to_do; - } + } /* Now write out the remainder. Normally, this will fit in the buffer, but it's somewhat messier for line-buffered files, |