]> pd.if.org Git - pdclib/blob - functions/stdlib/quick_exit.c
d315b0befca7bec6fbed609fe717d6590b0efa49
[pdclib] / functions / stdlib / quick_exit.c
1 /* quick_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 #include <_PDCLIB_io.h>
11
12 /* TODO - "except that a function is called after any previously registered
13    functions that had already been called at the time it was registered.
14 */
15
16 /* TODO: 32 is guaranteed. This should be dynamic but ATM gives problems
17    with my malloc.
18 */
19 #define NUMBER_OF_SLOTS 40
20
21 void (*_PDCLIB_quickexitstack[ NUMBER_OF_SLOTS ])( void ) = { 0 };
22 size_t _PDCLIB_quickexitptr = NUMBER_OF_SLOTS;
23
24 void quick_exit( int status )
25 {
26     while ( _PDCLIB_quickexitptr < NUMBER_OF_SLOTS )
27     {
28         _PDCLIB_quickexitstack[ _PDCLIB_quickexitptr++ ]();
29     }
30     _Exit( status );
31 }
32
33 #endif
34
35 #ifdef TEST
36 #include <_PDCLIB_test.h>
37
38 int main( void )
39 {
40     /* Unwinding of regstack tested in at_quick_exit(). */
41     return TEST_RESULTS;
42 }
43
44 #endif