How can I get the message for error codes returned by int ferror(FILE*)
? For errno
there is the char * strerror(int)
. What is it for codes returned by ferror? If char * strerror(int)
is good for that too, then I need a reference for it (I failed to find any indicator for this case).
Return Value The ferror() function returns a nonzero value to indicate an error on the given stream . A return value of 0 means that no error has occurred. This example puts data out to a stream, and then checks that a write error has not occurred.
In the C Programming Language, the ferror function tests to see if the error indicator has been set for a stream pointed to by stream.
Return Value If no error has occurred on stream, ferror returns 0. Otherwise, it returns a nonzero value. If stream is NULL, ferror invokes the invalid parameter handler, as described in Parameter Validation. If execution is allowed to continue, this function sets errno to EINVAL and returns 0.
If you need to report a reason for failure, add an extra int *errorcode argument and include if (errorcode) *errorcode = reason; at the end of your function to allow callers that don't care about the reason to pass a null pointer.
From this reference page:
The ferror() function shall test the error indicator for the stream pointed to by stream.
This means that ferror
returns a boolean that tells you if there is an error or not, nothing more. But according to the POSIX specification the value of errno
will contain an error code in case of a failure.
The library libexplain
can return strings for the ferror. https://linux.die.net/man/3/explain_ferror
From the docs:
if (ferror(fp) < 0)
{
fprintf(stderr, "%s\n", explain_ferror(fp));
exit(EXIT_FAILURE);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With