master
1/**
2 * This file has no copyright assigned and is placed in the Public Domain.
3 * This file is part of the mingw-w64 runtime package.
4 * No warranty is given; refer to the file DISCLAIMER.PD within this package.
5 */
6
7#include <windows.h>
8#include <stdlib.h>
9#include <setjmp.h>
10
11typedef void (*func_ptr) (void);
12extern func_ptr __CTOR_LIST__[];
13extern func_ptr __DTOR_LIST__[];
14
15void __do_global_dtors (void);
16void __do_global_ctors (void);
17void __main (void);
18
19void
20__do_global_dtors (void)
21{
22 static func_ptr *p = __DTOR_LIST__ + 1;
23
24 while (*p)
25 {
26 (*(p)) ();
27 p++;
28 }
29}
30
31void
32__do_global_ctors (void)
33{
34 unsigned long nptrs = (unsigned long) (ptrdiff_t) __CTOR_LIST__[0];
35 unsigned long i;
36
37 if (nptrs == (unsigned long) -1)
38 {
39 for (nptrs = 0; __CTOR_LIST__[nptrs + 1] != 0; nptrs++);
40 }
41
42 for (i = nptrs; i >= 1; i--)
43 {
44 __CTOR_LIST__[i] ();
45 }
46
47 atexit (__do_global_dtors);
48}
49
50static int initialized = 0;
51
52void
53__main (void)
54{
55 if (!initialized)
56 {
57 initialized = 1;
58 __do_global_ctors ();
59 }
60}