Use ferror()
to check for any accumulated errors, for example, after a long string of stdio
calls. The ferror()
function tests the error indicator for a specified stream and returns nonzero if and only if the error indicator is set for stream.
...
Many implementations of the stdio
package adjust their behavior slightly if stdout
is a terminal. To make the determination, these implementations perform some operation which happens to fail (with ENOTTY
) if stdout is not a terminal. Although the output operation goes on to complete successfully, errno
still contains ENOTTY
. This behavior can be mildly confusing, but it is not strictly incorrect, because it is only meaningful for a program to inspect the contents of errno after an error has been reported. (More precisely, errno
is only meaningful after a library function that sets errno
on error has returned an error code.)
...