diff options
author | Christopher Faylor <me@cgf.cx> | 2000-02-17 19:38:33 +0000 |
---|---|---|
committer | Christopher Faylor <me@cgf.cx> | 2000-02-17 19:38:33 +0000 |
commit | 1fd5e000ace55b323124c7e556a7a864b972a5c4 (patch) | |
tree | dc4fcf1e5e22a040716ef92c496b8d94959b2baa /winsup/mingw/gccmain.c | |
parent | 369d8a8fd5e887eca547bf34bccfdf755c9e5397 (diff) | |
download | cygnal-1fd5e000ace55b323124c7e556a7a864b972a5c4.tar.gz cygnal-1fd5e000ace55b323124c7e556a7a864b972a5c4.tar.bz2 cygnal-1fd5e000ace55b323124c7e556a7a864b972a5c4.zip |
import winsup-2000-02-17 snapshot
Diffstat (limited to 'winsup/mingw/gccmain.c')
-rw-r--r-- | winsup/mingw/gccmain.c | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/winsup/mingw/gccmain.c b/winsup/mingw/gccmain.c new file mode 100644 index 000000000..5c438e98a --- /dev/null +++ b/winsup/mingw/gccmain.c @@ -0,0 +1,85 @@ +/* + * gccmain.c + * + * A separate version of __main, __do_global_ctors and __do_global_dtors for + * Mingw32 for use with Cygwin32 b19. Hopefully this object file will only + * be linked if the libgcc.a doesn't include __main, __do_global_dtors and + * __do_global_ctors. + * + * This file is part of the Mingw32 package. + * + * Contributors: + * Code supplied by Stan Cox <scox@cygnus.com> + * + * $Revision$ + * $Author$ + * $Date$ + * + */ + +/* Needed for the atexit prototype. */ +#include <stdlib.h> + +typedef void (*func_ptr) (void); +extern func_ptr __CTOR_LIST__[]; +extern func_ptr __DTOR_LIST__[]; + +void +__do_global_dtors (void) +{ + static func_ptr *p = __DTOR_LIST__ + 1; + + /* + * Call each destructor in the destructor list until a null pointer + * is encountered. + */ + while (*p) + { + (*(p)) (); + p++; + } +} + +void +__do_global_ctors (void) +{ + unsigned long nptrs = (unsigned long) __CTOR_LIST__[0]; + unsigned i; + + /* + * If the first entry in the constructor list is -1 then the list + * is terminated with a null entry. Otherwise the first entry was + * the number of pointers in the list. + */ + if (nptrs == -1) + { + for (nptrs = 0; __CTOR_LIST__[nptrs + 1] != 0; nptrs++) + ; + } + + /* + * Go through the list backwards calling constructors. + */ + for (i = nptrs; i >= 1; i--) + { + __CTOR_LIST__[i] (); + } + + /* + * Register the destructors for processing on exit. + */ + atexit (__do_global_dtors); +} + +static int initialized = 0; + +void +__main (void) +{ + if (!initialized) + { + initialized = 1; + __do_global_ctors (); + } +} + |