Adding upstream version 4.00~pre54+dfsg.
[syslinux-debian/hramrach.git] / com32 / lib / onexit.c
blobd409e82e6a7528dfc43ddc03bbfcb77539d74938
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;