Initial revision
This commit is contained in:
42
lang/cem/libcc.ansi/stdlib/exit.c
Normal file
42
lang/cem/libcc.ansi/stdlib/exit.c
Normal file
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||
*/
|
||||
/* $Header$ */
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#define NEXITS 32
|
||||
|
||||
static void (*functab[NEXITS])(void);
|
||||
static int funccnt = 0;
|
||||
|
||||
extern void _cleanup(void);
|
||||
extern void _exit(int);
|
||||
|
||||
static void
|
||||
_calls(void)
|
||||
{
|
||||
register int i = funccnt;
|
||||
|
||||
/* "Called in reversed order of their registration" */
|
||||
while (--i >= 0)
|
||||
(*functab[i])();
|
||||
}
|
||||
|
||||
void
|
||||
exit(int status)
|
||||
{
|
||||
_calls();
|
||||
_cleanup() ;
|
||||
_exit(status) ;
|
||||
}
|
||||
|
||||
int
|
||||
atexit(void (*func)(void))
|
||||
{
|
||||
if (funccnt >= NEXITS)
|
||||
return 1;
|
||||
functab[funccnt++] = func;
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user