X-Git-Url: https://pd.if.org/git/?a=blobdiff_plain;f=functions%2Fstdlib%2Fexit.c;h=48a51118b34494ce2f9532a0e3005000b4294021;hb=cd6cfe0f578c4f744ddc9a342243aff6b42f8027;hp=520757d501bd04667ae2aa3380de297c0c0979c4;hpb=7842803c173209f48b087e149cae6204a48bb000;p=pdclib.old diff --git a/functions/stdlib/exit.c b/functions/stdlib/exit.c index 520757d..48a5111 100644 --- a/functions/stdlib/exit.c +++ b/functions/stdlib/exit.c @@ -1,7 +1,5 @@ /* $Id$ */ -/* Release $Name$ */ - /* exit( int ) This file is part of the Public Domain C Library (PDCLib). @@ -11,20 +9,26 @@ #include #ifndef REGTEST +#include <_PDCLIB_io.h> + +/* TODO - "except that a function is called after any previously registered + functions that had already been called at the time it was registered. +*/ + +/* TODO: 32 is guaranteed. This should be dynamic but ATM gives problems + with my malloc. +*/ +#define NUMBER_OF_SLOTS 40 -struct _PDCLIB_exitfunc_t * regstack = NULL; +void (*_PDCLIB_regstack[ NUMBER_OF_SLOTS ])( void ) = { _PDCLIB_closeall }; +size_t _PDCLIB_regptr = NUMBER_OF_SLOTS; void exit( int status ) { - struct _PDCLIB_exitfunc_t * next = regstack; - while ( next != NULL ) + while ( _PDCLIB_regptr < NUMBER_OF_SLOTS ) { - next->func(); - regstack = next->next; - free( next ); - next = regstack; + _PDCLIB_regstack[ _PDCLIB_regptr++ ](); } - /* TODO: Flush and close open streams. Remove tmpfile() files. */ _Exit( status ); } @@ -33,11 +37,9 @@ void exit( int status ) #ifdef TEST #include <_PDCLIB_test.h> -int main() +int main( void ) { - int NO_TESTDRIVER = 0; - BEGIN_TESTS; - TESTCASE( NO_TESTDRIVER ); + /* Unwinding of regstack tested in atexit(). */ return TEST_RESULTS; }