6 /* Ensure that at least 32 atexit handlers can be registered without malloc */
12 void (*f[COUNT])(void);
15 static int run_atexit_functions(void)
18 for (; head; head=head->next) {
19 for (i=COUNT-1; i>=0 && !head->f[i]; i--);
20 for (; i>=0; i--) head->f[i]();
25 int (*const __funcs_on_exit)(void) = run_atexit_functions;
27 int atexit(void (*func)(void))
32 /* Hook for atexit extensions */
33 if (libc.atexit) return libc.atexit(func);
37 /* Defer initialization of head so it can be in BSS */
38 if (!head) head = &builtin;
40 /* If the current function list is full, add a new one */
41 if (head->f[COUNT-1]) {
42 struct fl *new_fl = calloc(sizeof(struct fl), 1);
51 /* Append function to the list. */
52 for (i=0; i<COUNT && head->f[i]; i++);