No, there's no sense in doing a retry-loop like this if fread
or fwrite
returns fewer than the expected number of records read or written. That is to say, stdio is not like the low-level read
and write
operations that can result in "short" reads or writes.
If fread
returns fewer than the requested number of records, you've either hit EOF or a serious read error. You can distinguish between them by checking feof()
and ferror()
.
Similarly, if fwrite
returns fewer than the requested number of records, you've either run out of disk space or hit a serious write error.
In any case, due to buffering stdio makes it essentially impossible to know how much was successfully written, so if you encounter a write error, you usually need to consider the file lost and abort the whole operation.