[PATCH] fflush before ferror in copy.c
# HG changeset patch
# User Aron Griffis <agriffis@xxxxxxxxx>
# Date 1216441435 14400
# Branch HEAD
# Node ID dc1a21d442bb22effca9a2f7173314fc281d9fab
# Parent 7729b1ad530c8c1fde2e310bf991ef83cb9e8239
fflush before ferror in copy.c
David Laight points out that stdio writes almost never fail
unless the buffer fills up. To test for a file write error,
we need to either fclose or fflush. This patch adds calls to
fflush before ferror for each instance in copy.c
Signed-off-by: Aron Griffis <agriffis@xxxxxxxxx>
diff -r 7729b1ad530c -r dc1a21d442bb copy.c
--- a/copy.c Thu Jul 10 09:38:25 2008 -0400
+++ b/copy.c Sat Jul 19 00:23:55 2008 -0400
@@ -423,7 +423,7 @@
fputc ('\n', out); /* add header terminator */
}
- if (ferror (out) || feof (out))
+ if (fflush (out) || ferror (out) || feof (out))
return -1;
return 0;
@@ -526,7 +526,7 @@
fprintf (fpout, "Lines: %d\n", new_lines);
putc ('\n', fpout);
- if (ferror (fpout) || feof (fpout))
+ if (fflush (fpout) || ferror (fpout) || feof (fpout))
return -1;
new_offset = ftello (fpout);
@@ -689,7 +689,7 @@
if ((msg = mx_open_message (src, hdr->msgno)) == NULL)
return -1;
if ((r = _mutt_copy_message (fpout, msg->fp, hdr, hdr->content, flags,
chflags)) == 0
- && (ferror (fpout) || feof (fpout)))
+ && (fflush (fpout) || ferror (fpout) || feof (fpout)))
{
dprint (1, (debugfile, "_mutt_copy_message failed to detect EOF!\n"));
r = -1;
@@ -773,7 +773,7 @@
"Content-Type: message/external-body;
access-type=x-mutt-deleted;\n"
"\texpiration=%s; length=" OFF_T_FMT "\n"
"\n", date + 5, part->length);
- if (ferror (fpout))
+ if (fflush (fpout) || ferror (fpout))
return -1;
/* Copy the original mime headers */