summaryrefslogtreecommitdiff
path: root/libio/oldfileops.c
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2007-07-12 18:26:36 +0000
committerJakub Jelinek <jakub@redhat.com>2007-07-12 18:26:36 +0000
commit0ecb606cb6cf65de1d9fc8a919bceb4be476c602 (patch)
tree2ea1f8305970753e4a657acb2ccc15ca3eec8e2c /libio/oldfileops.c
parent7d58530341304d403a6626d7f7a1913165fe2f32 (diff)
2.5-18.1
Diffstat (limited to 'libio/oldfileops.c')
-rw-r--r--libio/oldfileops.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/libio/oldfileops.c b/libio/oldfileops.c
index b9efca7aa8..3bd0aa175b 100644
--- a/libio/oldfileops.c
+++ b/libio/oldfileops.c
@@ -1,4 +1,5 @@
-/* Copyright (C) 1993, 1995, 1997-2003, 2004 Free Software Foundation, Inc.
+/* Copyright (C) 1993, 1995, 1997-2004, 2005, 2007
+ Free Software Foundation, Inc.
This file is part of the GNU C Library.
Written by Per Bothner <bothner@cygnus.com>.
@@ -271,7 +272,7 @@ _IO_old_file_setbuf (fp, p, len)
return fp;
}
-static int old_do_write (_IO_FILE *, const char *, _IO_size_t) __THROW;
+static int old_do_write (_IO_FILE *, const char *, _IO_size_t);
/* Write TO_DO bytes from DATA to FP.
Then mark FP as having empty buffers. */
@@ -695,7 +696,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 +705,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 +722,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)
{
@@ -752,7 +755,7 @@ _IO_old_file_xsputn (f, data, n)
_IO_size_t block_size, do_write;
/* Next flush the (full) buffer. */
if (__overflow (f, EOF) == EOF)
- return n - to_do;
+ return to_do == 0 ? EOF : n - to_do;
/* Try to maintain alignment: write a whole number of blocks.
dont_write is what gets left over. */