From: Jens Axboe Date: Mon, 8 May 2006 05:13:39 +0000 (+0200) Subject: [PATCH] fread/fwrite error handling X-Git-Tag: blktrace-0.99.2~41 X-Git-Url: https://git.kernel.dk/?a=commitdiff_plain;h=1452478f2d1b27916c7cba6e3976ed2129533c73;p=blktrace.git [PATCH] fread/fwrite error handling Need to check ferror(), not return value. Thanks to Alex Polvi. --- diff --git a/blkrawverify.c b/blkrawverify.c index ca82707..93e8efa 100644 --- a/blkrawverify.c +++ b/blkrawverify.c @@ -169,6 +169,11 @@ static int process(FILE **fp, char *devname, char *file, unsigned int cpu) ofp = *fp; while ((n = fread(bit, sizeof(struct blk_io_trace), 1, ifp)) == 1) { + if (ferror(ifp)) { + clearerr(ifp); + perror("fread"); + break; + } if (data_is_native == -1) check_data_endianness(bit->magic); diff --git a/blktrace.c b/blktrace.c index cf67e7e..e345888 100644 --- a/blktrace.c +++ b/blktrace.c @@ -836,15 +836,11 @@ static int write_data(struct thread_information *tip, void *buf, if (!buf_len) return 0; - while (1) { - ret = fwrite(buf, buf_len, 1, tip->ofile); - if (ret == 1) - break; - - if (ret < 0) { - perror("write"); - return 1; - } + ret = fwrite(buf, buf_len, 1, tip->ofile); + if (ferror(tip->ofile) || ret != 1) { + perror("fwrite"); + clearerr(tip->ofile); + return 1; } if (tip->ofile_stdout)