fread() doesn't set errno, ferror need to be used to check for errors.
While at it, check if we read the expect number of elements.
Signed-off-by: Mathias Kresin <dev@kresin.me>
{
FILE *f;
int ret = EXIT_FAILURE;
+ size_t read;
f = fopen(fdata->file_name, "r");
if (f == NULL) {
goto out;
}
- errno = 0;
- fread(buf, fdata->file_size, 1, f);
- if (errno != 0) {
+ read = fread(buf, fdata->file_size, 1, f);
+ if (ferror(f) || read != 1) {
ERRS("unable to read from file \"%s\"", fdata->file_name);
goto out_close;
}