home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Education Sampler 1992 [NeXTSTEP]
/
Education_1992_Sampler.iso
/
NeXT
/
GnuSource
/
cc-61.0.1
/
cc
/
__main.c
next >
Wrap
C/C++ Source or Header
|
1991-04-08
|
1KB
|
69 lines
#include <sys/loader.h>
#include <libc.h>
#include <stdlib.h>
static void __do_global_init (void)
{
struct mach_header **header = getmachheaders ();
unsigned int i;
if (header == NULL)
return;
for (i = 0; header[i] != NULL; i++)
{
const struct section *section;
void (**constructor) (void);
unsigned int n, j;
section = getsectbynamefromheader (header[i],
"__TEXT",
"__constructor");
if (section == NULL)
continue;
constructor = (void (**) (void)) section->addr;
n = section->size / sizeof (long);
for (j = 0; j < n; j++)
(*constructor[j]) ();
}
}
static void __do_global_cleanup (void)
{
struct mach_header **header = getmachheaders ();
unsigned int i;
if (header == NULL)
return;
for (i = 0; header[i] != NULL; i++)
{
const struct section *section;
void (**destructor) (void);
unsigned int n, j;
section = getsectbynamefromheader (header[i],
"__TEXT",
"__destructor");
if (section == NULL)
continue;
destructor = (void (**) (void)) section->addr;
n = section->size / sizeof (long);
for (j = 0; j < n; j++)
(*destructor[j]) ();
}
}
void __main (void)
{
atexit (__do_global_cleanup);
__do_global_init ();
}