Mostly minor updates to the source tree for portcls.
[reactos.git] / reactos / lib / 3rdparty / mingw / gccmain.c
1 /*
2 * gccmain.c
3 * This file has no copyright assigned and is placed in the Public Domain.
4 * This file is a part of the mingw-runtime package.
5 * No warranty is given; refer to the file DISCLAIMER within the package.
6 *
7 * A separate version of __main, __do_global_ctors and __do_global_dtors for
8 * Mingw32 for use with Cygwin32 b19. Hopefully this object file will only
9 * be linked if the libgcc.a doesn't include __main, __do_global_dtors and
10 * __do_global_ctors.
11 *
12 */
13
14 /* Needed for the atexit prototype. */
15 #include <stdlib.h>
16
17 typedef void (*func_ptr) (void);
18 extern func_ptr __CTOR_LIST__[];
19 extern func_ptr __DTOR_LIST__[];
20
21 void
22 __do_global_dtors (void)
23 {
24 static func_ptr *p = __DTOR_LIST__ + 1;
25
26 /*
27 * Call each destructor in the destructor list until a null pointer
28 * is encountered.
29 */
30 while (*p)
31 {
32 (*(p)) ();
33 p++;
34 }
35 }
36
37 void
38 __do_global_ctors (void)
39 {
40 unsigned long nptrs = (unsigned long) __CTOR_LIST__[0];
41 unsigned i;
42
43 /*
44 * If the first entry in the constructor list is -1 then the list
45 * is terminated with a null entry. Otherwise the first entry was
46 * the number of pointers in the list.
47 */
48 if (nptrs == -1)
49 {
50 for (nptrs = 0; __CTOR_LIST__[nptrs + 1] != 0; nptrs++)
51 ;
52 }
53
54 /*
55 * Go through the list backwards calling constructors.
56 */
57 for (i = nptrs; i >= 1; i--)
58 {
59 __CTOR_LIST__[i] ();
60 }
61
62 /*
63 * Register the destructors for processing on exit.
64 */
65 atexit (__do_global_dtors);
66 }
67
68 static int initialized = 0;
69
70 void
71 __main (void)
72 {
73 if (!initialized)
74 {
75 initialized = 1;
76 __do_global_ctors ();
77 }
78 }
79