ferror
ferror is a C standard-I/O operation that tests whether a stream's error indicator is set.
A nonzero result means the indicator is set; zero means it is clear. This is stream status, not an errno value or a count of failed bytes. With a valid stream, testing the indicator does not change errno. [1]
Inspect the result of the I/O operation as well as the stream status. A retained indicator does not identify which earlier operation failed. Preserve failure information before clearerr or stream destruction. The glibc 2.39 implementation tests a flag under the stream's locking rules. [2]
Hesela's pinned glibc 2.39 and musl 1.2.5 comparison found a set indicator after a later zero-returning fflush. Its JSON normalizes ferror(stream) != 0 to 0 or 1; those values are not error numbers. This is a controlled API observation, not a storage durability test. [3]
Relations
Limitations
- A clear stream indicator does not establish durable storage completion.
- A set indicator does not identify the failing call or the number of affected bytes.