diff options
author | Jakob Kaivo <jkk@ung.org> | 2020-08-16 15:47:08 -0400 |
---|---|---|
committer | Jakob Kaivo <jkk@ung.org> | 2020-08-16 15:47:08 -0400 |
commit | 700fbd205a1a428677876d322606b9a354221892 (patch) | |
tree | c1a521f3a2ea0346f293a543a9ed4ef6c1242b77 /src/stdlib/at_quick_exit.c | |
parent | d36c832edee04db91e0c0ab635980c63844ca07c (diff) |
add skeleton of things from C11
Diffstat (limited to 'src/stdlib/at_quick_exit.c')
-rw-r--r-- | src/stdlib/at_quick_exit.c | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/src/stdlib/at_quick_exit.c b/src/stdlib/at_quick_exit.c new file mode 100644 index 00000000..01127d4e --- /dev/null +++ b/src/stdlib/at_quick_exit.c @@ -0,0 +1,54 @@ +#include <stdlib.h> +#include <limits.h> +#include <errno.h> +#include "_stdlib.h" + +/** register a function to run at quick exit **/ +int at_quick_exit(void (*func)(void)) +{ + __C_MIN(201112L); + if (__stdlib.nat_quick_exit >= ATEXIT_MAX) { + return 1; + } + + 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; + } + __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; + } + __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++; + + return 0; +} + +/*** +The fn(at_quick_exit) registers the function arg(func) to be called when the +program exits via fn(quick_exit). The function must take no parameters. +***/ + +/* UNSPECIFIED: - */ +/* UNDEFINED: - */ +/* IMPLEMENTATION: the number of registrations allowed (at least 32) */ +/* LOCALE: - */ + +/* RETURN(0): success */ +/* RETURN(NZ): failure */ +/* +STDC(201112) +*/ |