home *** CD-ROM | disk | FTP | other *** search
- /* main.c (emx+gcc) -- Copyright (c) 1992-1993 by Eberhard Mattes */
- /* Copyright (c) 1992-1993 by Kai Uwe Rommel */
-
- #include <stdlib.h>
-
- extern int *_ctor_ptr;
- extern int *_dtor_ptr;
-
- #if defined (__MT__)
- #define MAX_MODULES 64
- #else
- #define MAX_MODULES 1
- #endif
-
- static int *dtor_tab[MAX_MODULES];
- static int dtor_count = 0;
-
- static void call_tors (int *ptr)
- {
- int n;
- void (**ppf)();
-
- if (*ptr == -2) /* emxomf */
- for (ppf = (void (**)()) (ptr + 1); *ppf != NULL; ++ppf)
- (**ppf)();
- else
- {
- if (*ptr == -1) --ptr; /* Fix GNU ld bug */
- n = *ptr++; /* Get size of vector */
- if (*ptr == -1) /* First element must be -1, see crt0.s */
- for (ppf = (void (**)()) (ptr + 1); n > 1; ++ppf, --n)
- (**ppf)();
- }
- }
-
-
- static void call_dtors (void)
- {
- while (dtor_count > 0)
- {
- --dtor_count;
- call_tors (dtor_tab[dtor_count]);
- }
- }
-
-
- void __main (void)
- {
- int *tmp;
-
- tmp = _dtor_ptr; /* Maybe a ctor calls DosLoadModule... */
- call_tors (_ctor_ptr);
- if (dtor_count == 0)
- atexit (call_dtors);
- if (dtor_count < MAX_MODULES)
- dtor_tab[dtor_count++] = tmp;
- }
-