]> pd.if.org Git - pdclib/blob - functions/stdlib/exit.c
Added exit, _Exit, atexit.
[pdclib] / functions / stdlib / exit.c
1 /* $Id$ */
2
3 /* Release $Name$ */
4
5 /* exit( int )
6
7    This file is part of the Public Domain C Library (PDCLib).
8    Permission is granted to use, modify, and / or redistribute at will.
9 */
10
11 #include <stdlib.h>
12
13 #ifndef REGTEST
14
15 /* TODO: Required by both atexit() and exit(). */
16 struct _PDCLIB_exitfunc_t
17 {
18     struct _PDCLIB_exitfunc_t * next;
19     void (*func)( void );
20 };
21
22 struct _PDCLIB_exitfunc_t * regstack = NULL;
23
24 void exit( int status )
25 {
26     struct _PDCLIB_exitfunc_t * next = regstack;
27     while ( next != NULL )
28     {
29         next->func();
30         regstack = next->next;
31         free( next );
32         next = regstack;
33     }
34     /* TODO: Flush and close open streams. Remove tmpfile() files. */
35     _Exit( status );
36 }
37
38 #endif
39
40 #ifdef TEST
41 #include <_PDCLIB_test.h>
42
43 int main()
44 {
45     int NO_TESTDRIVER = 0;
46     BEGIN_TESTS;
47     TESTCASE( NO_TESTDRIVER );
48     return TEST_RESULTS;
49 }
50
51 #endif