O'Reilly logo

Advanced UNIX Programming by Warren W. Gay

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Testing for Errors Using stdio(3)

One area that is often overlooked in various texts that describe the stdio(3) set of routines is the proper treatment of errors. You have already seen how to discriminate between an error return and a success return with the fopen(3) call. Immediately after a fopen(3) failure, the value of errno contains the reason for the open failure. However, the situation may not be so clear in other circumstances, which will be examined next.

Pitfalls of the ferror(3) Function

By way of review, examine the function synopsis for the ferror(3) function:

#include <stdio.h>

int ferror(FILE *stream);                  /* Test stream for an error */
void clearerr(FILE *stream);               /* Clear an error indication */

The ferror(3) function returns a ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required