GNU Info

Info Node: (libc.info)Error Recovery

(libc.info)Error Recovery


Next: Binary Streams Prev: EOF and Errors Up: I/O on Streams
Enter node , (file) or (file)node

Recovering from errors
======================

   You may explicitly clear the error and EOF flags with the `clearerr'
function.

 - Function: void clearerr (FILE *STREAM)
     This function clears the end-of-file and error indicators for the
     stream STREAM.

     The file positioning functions (Note: File Positioning) also
     clear the end-of-file indicator for the stream.

 - Function: void clearerr_unlocked (FILE *STREAM)
     The `clearerr_unlocked' function is equivalent to the `clearerr'
     function except that it does not implicitly lock the stream.

     This function is a GNU extension.

   Note that it is _not_ correct to just clear the error flag and retry
a failed stream operation.  After a failed write, any number of
characters since the last buffer flush may have been committed to the
file, while some buffered data may have been discarded.  Merely retrying
can thus cause lost or repeated data.

   A failed read may leave the file pointer in an inappropriate
position for a second try.  In both cases, you should seek to a known
position before retrying.

   Most errors that can happen are not recoverable -- a second try will
always fail again in the same way.  So usually it is best to give up and
report the error to the user, rather than install complicated recovery
logic.

   One important exception is `EINTR' (Note: Interrupted Primitives).
Many stream I/O implementations will treat it as an ordinary error,
which can be quite inconvenient.  You can avoid this hassle by
installing all signals with the `SA_RESTART' flag.

   For similar reasons, setting nonblocking I/O on a stream's file
descriptor is not usually advisable.


automatically generated by info2www version 1.2.2.9