6 /* Ensure that at least 32 atexit handlers can be registered without malloc */
12 void (*f[COUNT])(void);
15 void __funcs_on_exit()
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]();
24 int atexit(void (*func)(void))
29 /* Hook for atexit extensions */
30 if (libc.atexit) return libc.atexit(func);
34 /* Defer initialization of head so it can be in BSS */
35 if (!head) head = &builtin;
37 /* If the current function list is full, add a new one */
38 if (head->f[COUNT-1]) {
39 struct fl *new_fl = calloc(sizeof(struct fl), 1);
48 /* Append function to the list. */
49 for (i=0; i<COUNT && head->f[i]; i++);