This documentation is copyright © 1998-2001 Sandro Sigala <sandro@sigala.it>.
All rights reserved.

Released under the GNU General Public License.

Return to index Return to header Previous symbol Next symbol

errno

Prototype

#include <errno.h>

#define errno	implementation-defined
or
extern int errno;

Description

The errno symbol holds the last error number set by several library functions. It may be implemented as a macro or as an identifier with external linkage. Please note that errno value is set to zero only at startup, and the user should set it to zero before a library function call, then inspect it before a subsequent library function call.

Example

View source
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void)
{
    FILE *f;

    /* Try to open an unexistent file. */
    if ((f = fopen("noexist.txt", "r")) == NULL) {
	    fprintf(stderr, "Cannot open: error number %d: %s\n",
		    errno, strerror(errno));
	    return EXIT_FAILURE;
    }
    fclose(f);

    return EXIT_SUCCESS;
}

References

ISO C 9899:1990 7.1.4