EXIT_SUCCESS, EXIT_FAILURE - termination status constants
Contents
Description
EXIT_SUCCESS and EXIT_FAILURE represent a successful and unsuccessful exit status respectively, and can
be used as arguments to the exit(3) function.
Examples
#include <stdio.h>
#include <stdlib.h>
int
main(int argc, char *argv[])
{
FILE *fp;
if (argc != 2) {
fprintf(stderr, "Usage: %s <file>\n", argv[0]);
exit(EXIT_FAILURE);
}
fp = fopen(argv[1], "r");
if (fp == NULL) {
perror(argv[1]);
exit(EXIT_FAILURE);
}
/* Other code omitted */
fclose(fp);
exit(EXIT_SUCCESS);
}
History
C89, POSIX.1-2001.
Library
Standard C library (libc)
Name
EXIT_SUCCESS, EXIT_FAILURE - termination status constants
See Also
exit(3), sysexits.h(3head) Linux man-pages 6.9.1 2024-06-15 EXIT_SUCCESS(3const)
Standards
C11, POSIX.1-2008.
Synopsis
#include<stdlib.h>#defineEXIT_SUCCESS 0
#defineEXIT_FAILURE /* nonzero */
