errno(5) File Formats Manual errno(5)
NAME
errno - Returns error condition value
SYNOPSIS
#include <errno.h>
DESCRIPTION
The errno external variable contains the most recent error condition set by a function. The symbolic values for errno are listed in the
intro reference page and in the ERRORS section of the individual reference pages for each function.
The exec() functions set errno to a value of 0 (zero) after successful completion. Typically, other functions only set errno to a nonzero
value.
EXAMPLES
The following program uses the value of errno to determine why the requested file could not be opened. If errno has one of the two tested
values, the program prints an appropriate message; otherwise, the program uses the error() function to print out the appropriate message.
This program does not have to set errno to a value of 0 (zero) because errno is tested only if the open() function has failed.
#include <errno.h> #include <stdio.h> #include <string.h> #include <fcntl.h> #include <sys/stat.h> #include <sys/types.h> #define SLENGTH
80
main() {
char filespec[SLENGTH], *eol;
int opret;
while (TRUE) {
printf("Enter file to be checked: ");
fgets(filespec, SLENGTH, stdin);
if ((eol = strchr(filespec, '
')) != NULL) {
*eol = '