abort() — Stop a Program
Format
#include <stdlib.h>
void abort(void);
Language Level
ANSI
Threadsafe
Yes
Description
The abort()
function
causes an abnormal end of the program and returns control to the host
environment. Like the exit()
function,
the abort()
function
deletes buffers and closes open files before ending the program.
Calls
to the abort()
function
raise the SIGABRT signal. The abort()
function
will not result in the ending of the program if SIGABRT is
caught by a signal handler, and the signal handler does not return.
Note: When
compiled with SYSIFCOPT(*ASYNCSIGNAL), the
abort()
function
cannot be called in a signal handler.Return Value
There is no return value.
Example
This example tests for successful
opening of the file myfile. If an error occurs, an error
message is printed, and the program ends with a call to the
abort()
function.
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
FILE *stream;
if ((stream = fopen("mylib/myfile", "r")) == NULL)
{
perror("Could not open data file");
abort();
}
}
Related Information
- exit() — End Program
- signal() — Handle Interrupt Signals
- <stdlib.h>
- See the
signal()
API in the APIs topic in the Information Center.