summaryrefslogtreecommitdiff
path: root/src/csplit.c
diff options
context:
space:
mode:
authorAssaf Gordon <assafgordon@gmail.com>2015-11-12 05:20:29 -0500
committerAssaf Gordon <assafgordon@gmail.com>2015-11-12 15:17:55 -0500
commit4c5c6cad85ad67d96df261ec9abdab66590d9ceb (patch)
treec73bb9ec4a84db74db3c511b19fb6353c5915406 /src/csplit.c
parent0daa359de8edd09fe2df76cb26c7cef16da52ce3 (diff)
downloadcoreutils-4c5c6cad85ad67d96df261ec9abdab66590d9ceb.tar.xz
csplit: check and report fwrite errors with errno
discussed in: http://lists.gnu.org/archive/html/coreutils/2015-10/msg00091.html * src/csplit.c: (save_line_to_file): check fwrite failures, report and exit immediately instead of deferring to 'close_output'. * tests/misc/csplit-io-err.sh: test fwrite failure using LD_PRELOAD. * tests/local.mk: add new test.
Diffstat (limited to 'src/csplit.c')
-rw-r--r--src/csplit.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/src/csplit.c b/src/csplit.c
index c97acb862..a2034bf77 100644
--- a/src/csplit.c
+++ b/src/csplit.c
@@ -1051,7 +1051,13 @@ close_output_file (void)
static void
save_line_to_file (const struct cstring *line)
{
- fwrite (line->str, sizeof (char), line->len, output_stream);
+ size_t l = fwrite (line->str, sizeof (char), line->len, output_stream);
+ if (l != line->len)
+ {
+ error (0, errno, _("write error for %s"), quoteaf (output_filename));
+ output_stream = NULL;
+ cleanup_fatal ();
+ }
bytes_written += line->len;
}