I'm trying to check when fread()
raises an error, so I use ferror()
.
chunk = fread(buf, 1, 100, file);
if (ferror(file))
{
return errno;
}
But, ferror()
man page (man 3 ferror
, or just man ferror
) says:
ERRORS
These functions should not fail and do not set the external variableerrno
.
So, how can I know the error type occurred when file has been read, although fread()
and ferror()
didn't set errno
?
ferror
can tell you an error happened, but sincefread
is not documented to seterrno
, how can he tell what the actual error was, if he can at all, sinceerrno
won't reflect the specific error condition that lit up the stream error state? – Salade