Commit | Line | Data |
---|---|---|
8d74f8fc JH |
1 | typedef void (*func_ptr) (void); |
2 | ||
3 | func_ptr __CTOR_LIST__[2]; | |
4 | func_ptr __DTOR_LIST__[2]; | |
5 | ||
6 | /* Run all the global destructors on exit from the program. */ | |
7 | ||
8 | static void | |
9 | __do_global_dtors () | |
10 | { | |
11 | unsigned nptrs = (unsigned long) __DTOR_LIST__[0]; | |
12 | unsigned i; | |
13 | ||
14 | /* Some systems place the number of pointers | |
15 | in the first word of the table. | |
16 | On other systems, that word is -1. | |
17 | In all cases, the table is null-terminated. */ | |
18 | ||
19 | /* If the length is not recorded, count up to the null. */ | |
20 | if (nptrs == -1) | |
21 | for (nptrs = 0; __DTOR_LIST__[nptrs + 1] != 0; nptrs++); | |
22 | ||
23 | /* GNU LD format. */ | |
24 | for (i = nptrs; i >= 1; i--) | |
25 | __DTOR_LIST__[i] (); | |
26 | ||
27 | } | |
28 | ||
29 | static void | |
30 | __do_global_ctors () | |
31 | { | |
32 | func_ptr *p; | |
33 | ||
34 | for (p = __CTOR_LIST__ + 1; *p; ) | |
35 | (*p++)(); | |
36 | atexit (__do_global_dtors); | |
37 | } | |
38 | ||
39 | __init() | |
40 | { | |
41 | static int initialized = 0; | |
42 | if (! initialized) { | |
43 | initialized = 1; | |
44 | __do_global_ctors (); | |
45 | } | |
46 | ||
47 | } |