libc/winsup/mingw/gccmain.c
Earnie Boyd 4d6c899474 * CONTRIBUTORS: New file.
* DISCLAIMER: Ditto.
	* CRT_noglob.c: Reword copyright and disclaimer.  Move Contributors
	section CONTRIBUTORS file.  Remove RCS tags.
	* CRTFmode.c: Ditto.
	* CRTglob.c: Ditto.
	* CRTinit.c: Ditto.
	* crt1.c: Ditto.
	* crtdll.dev: Ditto.
	* dllcrt1.c: Ditto.
	* dllmain.c: Ditto.
	* gccmain.c: Ditto.
	* init.c: Ditto.
	* isascii.c: Ditto.
	* iscsym.c: Ditto.
	* iscsymf.c: Ditto.
	* jamfile: Ditto.
	* main.c: Ditto.
	* msvcrt.def.in: Ditto.
	* strcasecmp.c: Ditto.
	* toascii.c: Ditto.
	* wcscmpi.c: Ditto.
	* include/assert.h: Ditto.
	* include/conio.h: Ditto.
	* include/ctype.h: Ditto.
	* include/direct.h: Ditto.
	* include/dirent.h: Ditto.
	* include/dos.h: Ditto.
	* include/errno.h: Ditto.
	* include/excpt.h: Ditto.
	* include/fcntl.h: Ditto.
	* include/float.h: Ditto.
	* include/io.h: Ditto.
	* include/locale.h: Ditto.
	* include/malloc.h: Ditto.
	* include/math.h: Ditto.
	* include/process.h: Ditto.
	* include/setjmp.h: Ditto.
	* include/share.h: Ditto.
	* include/signal.h: Ditto.
	* include/stdio.h: Ditto.
	* include/stdlib.h: Ditto.
	* include/string.h: Ditto.
	* include/tchar.h: Ditto.
	* include/time.h: Ditto.
	* include/wchar.h: Ditto.
	* include/sys/locking.h: Ditto.
	* include/sys/param.h: Ditto.
	* include/sys/stat.h: Ditto.
	* include/sys/timeb.h: Ditto.
	* include/sys/types.h: Ditto.
	* include/sys/utime.h: Ditto.
	* mingwex/dirent.c: Ditto.
2004-04-20 22:49:32 +00:00

80 lines
1.6 KiB
C

/*
* gccmain.c
* This file has no copyright assigned and is placed in the Public Domain.
* This file is a part of the mingw-runtime package.
* No warranty is given; refer to the file DISCLAIMER within the package.
*
* 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.
*
*/
/* 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 ();
}
}