They're not exactly equivalent.
fread()
was mis-designed. Its design ignores the possibilty of a partial read at the end of the file, which cannot be expressed by its return value, which is in units of the size you specified.
You should really only use fread()
where the size is 1 and the length is the number of bytes you're expecting. That's the only way you can properly deal with the situation. For types other than char
that means providing sizeof char
as the size and n*sizeof T
as the length, where n
is the number of T
s you are expecting.