2022-10-12 18:41:55 +00:00
|
|
|
#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;
|
|
|
|
}
|
|
|
|
|
2022-10-15 07:52:37 +00:00
|
|
|
__lc_noreturn void exit(int status)
|
2022-10-12 18:41:55 +00:00
|
|
|
{
|
|
|
|
for (int i = 0; i < atexit_function_count; i++) { atexit_functions[i](); }
|
|
|
|
_exit(status);
|
|
|
|
}
|
|
|
|
}
|