at_quick_exit()

Updated: April 19, 2023

Register functions to be called during program termination via quick_exit()

Synopsis:

#include <stdlib.h>

int at_quick_exit( void (*func)(void) );

Arguments:

func
A pointer to the function you want to be called when the program terminates via a call to quick_exit(). This function has no arguments and doesn't return a value; its prototype should be:
void func( void );

Library:

libc

Use the -l c option to qcc to link against this library. This library is usually included automatically.

Description:

The at_quick_exit() function registers a function to be called when the program terminates via a call to quick_exit(). If you register more than one function with at_quick_exit(), they're executed in a “last-in, first-out” order.

Note: The functions registered with at_quick_exit() aren't called when the program terminates with a call to _exit() or exit().

Returns:

0 for success, or nonzero if an error occurs.

Examples:

#include <stdio.h>
#include <stdlib.h>

void func1( void )
{
    printf( "last.\n" );
}

void func2( void )
{
    printf( "this " );
}

void func3( void )
{
    printf( "Do " );
}

int main( void )
{
    at_quick_exit( func1 );
    at_quick_exit( func2 );
    at_quick_exit( func3 );

    printf( "Do this first.\n" );

    quick_exit( EXIT_SUCCESS );
}

produces the output:

Do this first.
Do this last.

Classification:

C11

Safety:  
Cancellation point No
Interrupt handler No
Signal handler No
Thread Yes