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