[PATCH] fread/fwrite error handling
authorJens Axboe <axboe@suse.de>
Mon, 8 May 2006 05:13:39 +0000 (07:13 +0200)
committerJens Axboe <axboe@suse.de>
Mon, 8 May 2006 05:13:39 +0000 (07:13 +0200)
Need to check ferror(), not return value. Thanks to Alex Polvi.

blkrawverify.c
blktrace.c

index ca827072c8b854699d4da99d53c79dcd3fb8836d..93e8efa8312769bc19bada65bbb816d879ae9da6 100644 (file)
@@ -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);
 
index cf67e7e5d5634ebb06c12d7103cc5269958814e5..e34588828f59f03bad00aa770efeb8d520399fa9 100644 (file)
@@ -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)