summaryrefslogtreecommitdiff
path: root/src/__main.c
blob: 71a1c9e986c7d9c589db54ecb2b19d4ee66b951f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <stdlib.h>
#include <stdio.h>
#include <locale.h>
#include "stdio/_stdio.h"
#include "stdlib/_stdlib.h"

#ifdef _POSIX_SOURCE
#define DEFAULT_LOCALE "POSIX"
#else
#define DEFAULT_LOCALE "C"
#endif

void __main(int argc, char **argv)
{
	extern int main(int, char*[]);

	#ifdef _POSIX_SOURCE
	extern char **environ;
	environ = argv + argc + 1;
	__stdlib.environ = environ;
	#else
	__stdlib.environ = argv + argc + 1;
	#endif

	stdin = __stdio.FILES + 0;
	stdin->fd = 0;
	freopen(NULL, "r", stdin);

	stdout = __stdio.FILES + 1;
	stdout->fd = 1;
	freopen(NULL, "w", stdout);

	stderr = __stdio.FILES + 2;
	stderr->fd = 2;
	freopen(NULL, "w", stderr);
	setvbuf(stderr, NULL, _IONBF, 0);

	setlocale(LC_ALL, DEFAULT_LOCALE);

	exit(main(argc, argv));
}

void __stack_chk_fail(void) {}