Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Use ferror() rather than errno to check whether an error has occurred on a file stream , for example, (after a long string of stdio calls, for example). 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 that 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.)

...

Wiki Markup
\[[Horton 90|AA. C References#Horton 90]\] Section 14, p. 254
\[[ISO/IEC 9899-1999|AA. C References#ISO/IEC 9899-1999]\] Section 6.3.1.1, "Boolean, characters, and integers,", Section  7.1.4, and Section 7.9.10.3
\[[ISO/IEC PDTR 24772|AA. C References#ISO/IEC PDTR 24772]\] "NZN Returning error status"
\[[Koenig 89|AA. C References#Koenig 89]\] Section 5.4, p. 73

...

ERR00-A. Adopt and implement a consistent and comprehensive error handling policy      12. Error Handling (ERR)       ERR02-A. Avoid in-band error indicators