There are quite a few basic confusions in that code.
ftell()
returnslong
, notint
. Also it should beconst
, since the file's size is assumed not to change while we read it.- There's no need to call
rewind()
and usefseek()
to offset 0. - Don't cast the return value of
malloc()
in C. - You are not dealing with strings, so don't add one for some "terminator".
- Don't scale allocations by
sizeof (char)
, that's always 1. - Check that the allocation succeeds before relying on the result.
- Don't cast the buffer pointer to
void *
infread()
, that's completely pointless. - Use the file length in the
fread()
, callingstrlen()
on an undefined pointer is undefined behavior. - Verify that the
fread()
succeeds.