scc

A fork of https://git.simple-cc.org/scc/ for Qute

git clone https://git.8pit.net/scc.git

 1#include <stdlib.h>
 2#include <errno.h>
 3
 4#include "../libc.h"
 5
 6#undef atexit
 7
 8static void (*funs[_ATEXIT_MAX])(void);
 9static unsigned nfuns;
10
11static void
12callhdls(void)
13{
14	while (nfuns > 0)
15		(*funs[--nfuns])();
16}
17
18int
19atexit(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}