From cae6ebb2c9d01846d4f5085590dd5c0893825773 Mon Sep 17 00:00:00 2001 From: Ulrich Drepper Date: Tue, 27 Sep 2005 19:40:49 +0000 Subject: [BZ #1078] 2005-09-27 Ulrich Drepper [BZ #1078] * libio/fileops.c (_IO_new_file_xsputn): Determine amount of available space in non-line-buffered buffer correctly. * libio/oldfileops.c (_IO_old_file_xsputn): Likewise. * stdio-common/Makefile (tests): Add tst-fwrite. * stdio-common/tst-fwrite.c: New file. --- libio/oldfileops.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'libio/oldfileops.c') diff --git a/libio/oldfileops.c b/libio/oldfileops.c index 2dd6182..cd54ea5 100644 --- a/libio/oldfileops.c +++ b/libio/oldfileops.c @@ -695,7 +695,7 @@ _IO_old_file_xsputn (f, data, n) register const char *s = (char *) data; _IO_size_t to_do = n; int must_flush = 0; - _IO_size_t count; + _IO_size_t count = 0; if (n <= 0) return 0; @@ -704,7 +704,6 @@ _IO_old_file_xsputn (f, data, n) (or the filebuf is unbuffered), use sys_write directly. */ /* First figure out how much space is available in the buffer. */ - count = f->_IO_write_end - f->_IO_write_ptr; /* Space available. */ if ((f->_flags & _IO_LINE_BUF) && (f->_flags & _IO_CURRENTLY_PUTTING)) { count = f->_IO_buf_end - f->_IO_write_ptr; @@ -722,6 +721,9 @@ _IO_old_file_xsputn (f, data, n) } } } + else if (f->_IO_write_end > f->_IO_write_ptr) + count = f->_IO_write_end - f->_IO_write_ptr; /* Space available. */ + /* Then fill the buffer. */ if (count > 0) { -- cgit v1.1