diff options
| author | Jakob Kaivo <jkk@ung.org> | 2024-01-31 01:11:36 -0500 |
|---|---|---|
| committer | Jakob Kaivo <jkk@ung.org> | 2024-01-31 01:11:36 -0500 |
| commit | 5ca5b53beccb061a4390d23493e670d9f8b65cd7 (patch) | |
| tree | 8ab5d59341e41c7eceb02b2cb2272adc37fd5ef8 /src/stdlib/at_quick_exit.c | |
| parent | d2b6b441366cb56785a92694e19a084642c1c99e (diff) | |
fix up exit()/quick_exit() handlers
Diffstat (limited to 'src/stdlib/at_quick_exit.c')
| -rw-r--r-- | src/stdlib/at_quick_exit.c | 37 |
1 files changed, 13 insertions, 24 deletions
diff --git a/src/stdlib/at_quick_exit.c b/src/stdlib/at_quick_exit.c index e3ae86cc..6a6db796 100644 --- a/src/stdlib/at_quick_exit.c +++ b/src/stdlib/at_quick_exit.c @@ -8,32 +8,21 @@ int at_quick_exit(void (*func)(void)) { SIGNAL_SAFE(0); - (void)func; - - /* - if (__stdlib.at_quick_exit == NULL) { - __stdlib.at_quick_exit = calloc(1, - sizeof(*__stdlib.at_quick_exit)); - if (__stdlib.at_quick_exit == NULL) { - errno = ENOMEM; - return 1; + struct atexit *ae = &(__stdlib.at_quick_exit); + while (ae->nfns == sizeof(ae->fns) / sizeof(ae->fns[0])) { + if (ae->next == NULL) { + ae->next = calloc(1, sizeof(*ae->next)); + if (ae->next == NULL) { + #ifdef ENOMEM + errno = ENOMEM; + #endif + return 1; + } + ae->next->prev = ae; } - __stdlib.at_quick_exit->fn = func; - __stdlib.nat_quick_exit = 1; - return 0; - } - - __stdlib.at_quick_exit->next = calloc(1, - sizeof(*__stdlib.at_quick_exit->next)); - if (__stdlib.at_quick_exit->next == NULL) { - errno = ENOMEM; - return 1; + ae = ae->next; } - __stdlib.at_quick_exit->next->fn = func; - __stdlib.at_quick_exit->next->prev = __stdlib.at_quick_exit; - __stdlib.at_quick_exit = __stdlib.at_quick_exit->next; - __stdlib.nat_quick_exit++; - */ + ae->fns[ae->nfns++] = func; return 0; } |
