check the return value when calling fread()

this suppress compiler warnings in come cases and is an extra check
to ensure that the whole file has been read