Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alexbevi
GitHub Repository: alexbevi/BizHawk
Path: blob/master/waterbox/libc/functions/stdlib/atexit.c
2 views
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_exitstack[])( void );
12
extern size_t _PDCLIB_exitptr;
13
14
int atexit( void (*func)( void ) )
15
{
16
if ( _PDCLIB_exitptr == 0 )
17
{
18
return -1;
19
}
20
else
21
{
22
_PDCLIB_exitstack[ --_PDCLIB_exitptr ] = func;
23
return 0;
24
}
25
}
26
27
#endif
28
29
#ifdef TEST
30
#include "_PDCLIB_test.h"
31
#include <assert.h>
32
33
static int flags[ 32 ];
34
35
static void counthandler( void )
36
{
37
static int count = 0;
38
flags[ count ] = count;
39
++count;
40
}
41
42
static void checkhandler( void )
43
{
44
for ( int i = 0; i < 31; ++i )
45
{
46
assert( flags[ i ] == i );
47
}
48
}
49
50
int main( void )
51
{
52
TESTCASE( atexit( &checkhandler ) == 0 );
53
for ( int i = 0; i < 31; ++i )
54
{
55
TESTCASE( atexit( &counthandler ) == 0 );
56
}
57
return TEST_RESULTS;
58
}
59
60
#endif
61
62