apio
8398b2e2e4
That way, we don't pollute user programs with our own 'noreturn' and 'deprecated' macros
25 lines
558 B
C++
25 lines
558 B
C++
#include <stdlib.h>
|
|
#include <unistd.h>
|
|
|
|
#define ATEXIT_MAX_FUNCS 32
|
|
|
|
typedef void (*atexit_func_t)(void);
|
|
|
|
atexit_func_t atexit_functions[ATEXIT_MAX_FUNCS];
|
|
int atexit_function_count = 0;
|
|
|
|
extern "C"
|
|
{
|
|
int atexit(atexit_func_t handler)
|
|
{
|
|
if (atexit_function_count >= ATEXIT_MAX_FUNCS) return -1;
|
|
atexit_functions[atexit_function_count++] = handler;
|
|
return 0;
|
|
}
|
|
|
|
__lc_noreturn void exit(int status)
|
|
{
|
|
for (int i = 0; i < atexit_function_count; i++) { atexit_functions[i](); }
|
|
_exit(status);
|
|
}
|
|
} |