]> pd.if.org Git - pdclib/blob - functions/stdlib/exit.c
Comment cleanups.
[pdclib] / functions / stdlib / exit.c
1 /* exit( int )
2
3    This file is part of the Public Domain C Library (PDCLib).
4    Permission is granted to use, modify, and / or redistribute at will.
5 */
6
7 #include <stdlib.h>
8
9 #ifndef REGTEST
10
11 /* TODO - "except that a function is called after any previously registered
12    functions that had already been called at the time it was registered.
13 */
14
15 /* TODO: 32 is guaranteed. This should be dynamic but ATM gives problems
16    with my malloc.
17 */
18 #define NUMBER_OF_SLOTS 40
19
20 void (*_PDCLIB_regstack[ NUMBER_OF_SLOTS ])( void ) = { _PDCLIB_closeall };
21 size_t _PDCLIB_regptr = NUMBER_OF_SLOTS;
22
23 void exit( int status )
24 {
25     while ( _PDCLIB_regptr < NUMBER_OF_SLOTS )
26     {
27         _PDCLIB_regstack[ _PDCLIB_regptr++ ]();
28     }
29     _Exit( status );
30 }
31
32 #endif
33
34 #ifdef TEST
35 #include <_PDCLIB_test.h>
36
37 int main( void )
38 {
39     /* Unwinding of regstack tested in atexit(). */
40     return TEST_RESULTS;
41 }
42
43 #endif