]> pd.if.org Git - pdclib/blob - functions/stdlib/exit.c
Whitespace 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
36 #include "_PDCLIB_test.h"
37
38 int main( void )
39 {
40     /* Unwinding of regstack tested in atexit(). */
41     return TEST_RESULTS;
42 }
43
44 #endif