]> pd.if.org Git - pdclib/blob - functions/stdlib/atexit.c
Added exit, _Exit, atexit.
[pdclib] / functions / stdlib / atexit.c
1 /* $Id$ */
2
3 /* Release $Name$ */
4
5 /* atexit( void (*)( void ) )
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 extern struct _PDCLIB_exitfunc_t * regstack;
23
24 int atexit( void (*func)( void ) )
25 {
26     struct _PDCLIB_exitfunc_t * regfunc = (struct _PDCLIB_exitfunc_t *)malloc( sizeof( struct _PDCLIB_exitfunc_t ) );
27     if ( regfunc == NULL )
28     {
29         return -1;
30     }
31     else
32     {
33         regfunc->func = func;
34         regfunc->next = regstack;
35         regstack = regfunc;
36         return 0;
37     }
38 }
39
40 #endif
41
42 #ifdef TEST
43 #include <_PDCLIB_test.h>
44
45 int main()
46 {
47     int NO_TESTDRIVER = 0;
48     BEGIN_TESTS;
49     TESTCASE( NO_TESTDRIVER );
50     return TEST_RESULTS;
51 }
52
53 #endif