2023-07-21 20:56:03 +00:00
|
|
|
#include <stdio.h>
|
2023-01-06 18:40:25 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
typedef void (*atexit_func_t)(void);
|
|
|
|
|
|
|
|
const int ATEXIT_MAX_FUNCS = 48;
|
|
|
|
|
|
|
|
int atexit_registered_funcs = 0;
|
|
|
|
|
|
|
|
atexit_func_t atexit_funcs[ATEXIT_MAX_FUNCS];
|
|
|
|
|
|
|
|
extern "C"
|
|
|
|
{
|
|
|
|
int atexit(atexit_func_t func)
|
|
|
|
{
|
|
|
|
if (atexit_registered_funcs == ATEXIT_MAX_FUNCS) return -1;
|
|
|
|
|
|
|
|
atexit_funcs[atexit_registered_funcs++] = func;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
__noreturn void exit(int status)
|
|
|
|
{
|
|
|
|
while (atexit_registered_funcs--) { atexit_funcs[atexit_registered_funcs](); }
|
|
|
|
|
2023-07-21 20:56:03 +00:00
|
|
|
fflush(NULL);
|
|
|
|
|
2023-01-06 18:40:25 +00:00
|
|
|
_Exit(status);
|
|
|
|
}
|
|
|
|
}
|