diff options
| author | Rich Felker <dalias@aerifal.cx> | 2011-02-12 00:22:29 -0500 | 
|---|---|---|
| committer | Rich Felker <dalias@aerifal.cx> | 2011-02-12 00:22:29 -0500 | 
| commit | 0b44a0315b47dd8eced9f3b7f31580cf14bbfc01 (patch) | |
| tree | 6eaef0d8a720fa3da580de87b647fff796fe80b3 /src/env/__libc_start_main.c | |
| download | musl-0b44a0315b47dd8eced9f3b7f31580cf14bbfc01.tar.gz | |
initial check-in, version 0.5.0v0.5.0
Diffstat (limited to 'src/env/__libc_start_main.c')
| -rw-r--r-- | src/env/__libc_start_main.c | 26 | 
1 files changed, 26 insertions, 0 deletions
diff --git a/src/env/__libc_start_main.c b/src/env/__libc_start_main.c new file mode 100644 index 00000000..70af77b5 --- /dev/null +++ b/src/env/__libc_start_main.c @@ -0,0 +1,26 @@ +#include "libc.h" + +/* Any use of __environ/environ will override this symbol. */ +char **__dummy_environ = (void *)-1; +weak_alias(__dummy_environ, ___environ); + +int __libc_start_main( +	int (*main)(int, char **, char **), int argc, char **argv, +	int (*init)(int, char **, char **), void (*fini)(void), +	void (*ldso_fini)(void)) +{ +	/* Save the environment if it may be used by libc/application */ +	char **envp = argv+argc+1; +	if (___environ != (void *)-1) ___environ = envp; + +	/* Avoid writing 0 and triggering unnecessary COW */ +	if (ldso_fini) libc.ldso_fini = ldso_fini; +	if (fini) libc.fini = fini; + +	/* Execute constructors (static) linked into the application */ +	if (init) init(argc, argv, envp); + +	/* Pass control to to application */ +	exit(main(argc, argv, envp)); +	return 0; +}  | 
