Luna/libc/src/atexit.cpp
apio c3653cd4e6
All checks were successful
continuous-integration/drone/push Build is passing
More stdlib.h implementation + commenting + atexit()
2023-01-06 19:40:25 +01:00

29 lines
541 B
C++

#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](); }
_Exit(status);
}
}