Use ferror instead of checking errno to detect errors in read_file

glibc sets errno even though the file read did not have an error
Fixes #1731