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