From a7925a24fe104a2ab54fb8a6bdec1e5cf80a8db7 Mon Sep 17 00:00:00 2001 From: Ulrich Drepper Date: Wed, 9 Apr 2008 07:42:19 +0000 Subject: [PATCH] [BZ #5998] 2008-04-09 Ulrich Drepper [BZ #5998] * libio/iofwrite.c (_IO_fwrite): Return correct count if flushing in line-buffered stream failed. * libio/iofwrite_u.c (fwrite_unlocked): Likewise. --- ChangeLog | 7 +++++++ libio/iofwrite.c | 8 ++++++-- libio/iofwrite_u.c | 8 ++++++-- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index b9a0b74..f7a47ef 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2008-04-09 Ulrich Drepper + + [BZ #5998] + * libio/iofwrite.c (_IO_fwrite): Return correct count if flushing + in line-buffered stream failed. + * libio/iofwrite_u.c (fwrite_unlocked): Likewise. + 2008-04-08 Ulrich Drepper [BZ #6024] diff --git a/libio/iofwrite.c b/libio/iofwrite.c index 1f4331c..fb91d6f 100644 --- a/libio/iofwrite.c +++ b/libio/iofwrite.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1993, 1996, 1997, 1998, 1999, 2000, 2002, 2003 +/* Copyright (C) 1993, 1996, 1997, 1998, 1999, 2000, 2002, 2003, 2008 Free Software Foundation, Inc. This file is part of the GNU C Library. @@ -44,7 +44,11 @@ _IO_fwrite (buf, size, count, fp) if (_IO_vtable_offset (fp) != 0 || _IO_fwide (fp, -1) == -1) written = _IO_sputn (fp, (const char *) buf, request); _IO_release_lock (fp); - if (written == request) + /* We have written all of the input in case the return value indicates + this or EOF is returned. The latter is a special case where we + simply did not manage to flush the buffer. But the data is in the + buffer and therefore written as far as fwrite is concerned. */ + if (written == request || written == EOF) return count; else return written / size; diff --git a/libio/iofwrite_u.c b/libio/iofwrite_u.c index 738cc5b..d27c02a 100644 --- a/libio/iofwrite_u.c +++ b/libio/iofwrite_u.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1993, 1996-2000, 2002 Free Software Foundation, Inc. +/* Copyright (C) 1993, 1996-2000, 2002, 2008 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -45,7 +45,11 @@ fwrite_unlocked (buf, size, count, fp) if (_IO_fwide (fp, -1) == -1) { written = _IO_sputn (fp, (const char *) buf, request); - if (written == request) + /* We have written all of the input in case the return value indicates + this or EOF is returned. The latter is a special case where we + simply did not manage to flush the buffer. But the data is in the + buffer and therefore written as far as fwrite is concerned. */ + if (written == request || written == EOF) return count; } -- 2.7.4