#ifndef REGTEST
-extern struct _PDCLIB_exitfunc_t * regstack;
+extern void (*_PDCLIB_regstack[])( void );
+extern size_t _PDCLIB_regptr;
int atexit( void (*func)( void ) )
{
- struct _PDCLIB_exitfunc_t * regfunc = (struct _PDCLIB_exitfunc_t *)malloc( sizeof( struct _PDCLIB_exitfunc_t ) );
- if ( regfunc == NULL )
+ if ( _PDCLIB_regptr == 0 )
{
return -1;
}
else
{
- regfunc->func = func;
- regfunc->next = regstack;
- regstack = regfunc;
+ _PDCLIB_regstack[ --_PDCLIB_regptr ] = func;
return 0;
}
}
functions that had already been called at the time it was registered.
*/
-struct _PDCLIB_exitfunc_t * regstack = NULL;
+/* TODO: 32 is guaranteed. This should be dynamic but ATM gives problems
+ with my malloc.
+*/
+#define NUMBER_OF_SLOTS 40
+
+void (*_PDCLIB_regstack[ NUMBER_OF_SLOTS ])( void );
+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++ ]();
}
_Exit( status );
}