atexit.c - scc - simple c99 compiler
(HTM) git clone git://git.simple-cc.org/scc
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) Submodules
(DIR) README
(DIR) LICENSE
---
atexit.c (369B)
---
1 #include <stdlib.h>
2 #include <errno.h>
3
4 #include "../libc.h"
5
6 #undef atexit
7
8 static void (*funs[_ATEXIT_MAX])(void);
9 static unsigned nfuns;
10
11 static void
12 callhdls(void)
13 {
14 while (nfuns > 0)
15 (*funs[--nfuns])();
16 }
17
18 int
19 atexit(void (*fun)(void))
20 {
21 if (nfuns == _ATEXIT_MAX) {
22 errno = ENOMEM;
23 return -1;
24 }
25 funs[nfuns++] = fun;
26 _atexithdl = callhdls;
27
28 return 0;
29 }