From 34c5e4a1f1de2e755311855c1b15d1f35a1bd61f Mon Sep 17 00:00:00 2001 From: Ulrich Drepper Date: Sun, 4 Sep 2005 20:10:35 +0000 Subject: * stdio-common/Makefile (tests): Add tst-put-error. * stdio-common/tst-put-error.c: New file. * libio/fileops.c (_IO_new_file_xsputn): If overflow fails and no more data would have to be written signal error. * libio/oldfileops.c (_IO_old_file_xsputn): Likewise. * libio/fileops.c (_IO_new_file_overflow): Use NULL not 0. --- libio/fileops.c | 10 ++++++---- libio/oldfileops.c | 4 ++-- 2 files changed, 8 insertions(+), 6 deletions(-) (limited to 'libio') diff --git a/libio/fileops.c b/libio/fileops.c index 19151cf188..3ad9b74011 100644 --- a/libio/fileops.c +++ b/libio/fileops.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1993, 1995, 1997-2003, 2004 Free Software Foundation, Inc. +/* Copyright (C) 1993, 1995, 1997-2004, 2005 Free Software Foundation, Inc. This file is part of the GNU C Library. Written by Per Bothner . @@ -826,10 +826,10 @@ _IO_new_file_overflow (f, ch) return EOF; } /* If currently reading or no buffer allocated. */ - if ((f->_flags & _IO_CURRENTLY_PUTTING) == 0 || f->_IO_write_base == 0) + if ((f->_flags & _IO_CURRENTLY_PUTTING) == 0 || f->_IO_write_base == NULL) { /* Allocate a buffer if needed. */ - if (f->_IO_write_base == 0) + if (f->_IO_write_base == NULL) { INTUSE(_IO_doallocbuf) (f); _IO_setg (f, f->_IO_buf_base, f->_IO_buf_base, f->_IO_buf_base); @@ -1338,7 +1338,9 @@ _IO_new_file_xsputn (f, data, n) _IO_size_t block_size, do_write; /* Next flush the (full) buffer. */ if (_IO_OVERFLOW (f, EOF) == EOF) - return n - to_do; + /* If nothing else has to be written we must not signal the + caller that everything has been written. */ + 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. */ diff --git a/libio/oldfileops.c b/libio/oldfileops.c index b9efca7aa8..2dd618215b 100644 --- a/libio/oldfileops.c +++ b/libio/oldfileops.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1993, 1995, 1997-2003, 2004 Free Software Foundation, Inc. +/* Copyright (C) 1993, 1995, 1997-2004, 2005 Free Software Foundation, Inc. This file is part of the GNU C Library. Written by Per Bothner . @@ -752,7 +752,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 ? 0 : n - to_do; /* Try to maintain alignment: write a whole number of blocks. dont_write is what gets left over. */ -- cgit 1.4.1