cleanup: Fix fread() and fwrite() error handling

Cleaned up some of the incorrect uses of fread() and fwrite(), mostly in
the format modules. Neither of these functions will ever return a value
less than 0, which we were checking for in some cases.

I've introduced a fair amount of duplication in the format modules, but
I plan to change how format modules work internally in a subsequent
patch set, so this is simply a stop-gap.

Change-Id: I8ca1cd47c20b2c0b72088bd13b9046f6977aa872
This commit is contained in:
Sean Bright
2017-04-21 13:04:44 -04:00
parent f7ca69809a
commit 1b50df78d0
21 changed files with 227 additions and 70 deletions

View File

@@ -856,16 +856,16 @@ static int b64_inbuf(struct b64_baseio *bio, FILE *fi)
if (bio->ateof)
return 0;
if ((l = fread(bio->iobuf, 1, B64_BASEMAXINLINE,fi)) <= 0) {
if (ferror(fi))
return -1;
if ((l = fread(bio->iobuf, 1, B64_BASEMAXINLINE, fi)) != B64_BASEMAXINLINE) {
bio->ateof = 1;
return 0;
if (l == 0) {
/* Assume EOF */
return 0;
}
}
bio->iolen= l;
bio->iocp= 0;
bio->iolen = l;
bio->iocp = 0;
return 1;
}