Adding upstream version 3.35.
[syslinux-debian/hramrach.git] / com32 / lib / onexit.c
blobc9847927ef1e16f0621d109d71251c7bd54355c6
1 /*
2 * onexit.c
3 */
5 #include <stdlib.h>
6 #include <unistd.h>
7 #include "atexit.h"
9 extern __noreturn (*__exit_handler)(int);
10 static struct atexit *__atexit_list;
12 static __noreturn on_exit_exit(int rv)
14 struct atexit *ap;
16 for ( ap = __atexit_list ; ap ; ap = ap->next ) {
17 ap->fctn(rv, ap->arg); /* This assumes extra args are harmless */
20 _exit(rv);
23 int on_exit(void (*fctn)(int, void *), void *arg)
25 struct atexit *as = malloc(sizeof(struct atexit));
27 if ( !as )
28 return -1;
30 as->fctn = fctn;
31 as->arg = arg;
33 as->next = __atexit_list;
34 __atexit_list = as;
36 __exit_handler = on_exit_exit;
38 return 0;