]> pd.if.org Git - pdclib/blob - functions/stdlib/exit.c
Added test driver.
[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 - "except that a function is called after any previously registered
16    functions that had already been called at the time it was registered.
17 */
18
19 struct _PDCLIB_exitfunc_t * regstack = NULL;
20
21 void exit( int status )
22 {
23     struct _PDCLIB_exitfunc_t * next = regstack;
24     while ( next != NULL )
25     {
26         next->func();
27         regstack = next->next;
28         free( next );
29         next = regstack;
30     }
31     _Exit( status );
32 }
33
34 #endif
35
36 #ifdef TEST
37 #include <_PDCLIB_test.h>
38
39 int main()
40 {
41     BEGIN_TESTS;
42     /* Unwinding of regstack tested in atexit(). */
43     return TEST_RESULTS;
44 }
45
46 #endif