]> pd.if.org Git - pdclib/blob - functions/stdlib/atexit.c
Whitespace cleanups.
[pdclib] / functions / stdlib / atexit.c
1 /* atexit( void (*)( void ) )
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
11 extern void (*_PDCLIB_regstack[])( void );
12 extern size_t _PDCLIB_regptr;
13
14 int atexit( void (*func)( void ) )
15 {
16     if ( _PDCLIB_regptr == 0 )
17     {
18         return -1;
19     }
20     else
21     {
22         _PDCLIB_regstack[ --_PDCLIB_regptr ] = func;
23         return 0;
24     }
25 }
26
27 #endif
28
29 #ifdef TEST
30
31 #include "_PDCLIB_test.h"
32
33 #include <assert.h>
34
35 static int flags[ 32 ];
36
37 static void counthandler( void )
38 {
39     static int count = 0;
40     flags[ count ] = count;
41     ++count;
42 }
43
44 static void checkhandler( void )
45 {
46     for ( int i = 0; i < 31; ++i )
47     {
48         assert( flags[ i ] == i );
49     }
50 }
51
52 int main( void )
53 {
54     TESTCASE( atexit( &checkhandler ) == 0 );
55     for ( int i = 0; i < 31; ++i )
56     {
57         TESTCASE( atexit( &counthandler ) == 0 );
58     }
59     return TEST_RESULTS;
60 }
61
62 #endif