blob: a6dbf347fb01ba107b1ffd7540723c8746fe25d4 (
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
/* go-main.c -- the main function for a Go program.
Copyright 2009 The Go Authors. All rights reserved.
Use of this source code is governed by a BSD-style
license that can be found in the LICENSE file. */
#include "config.h"
#include <stdlib.h>
#include <time.h>
#ifdef HAVE_FPU_CONTROL_H
#include <fpu_control.h>
#endif
#include "go-alloc.h"
#include "array.h"
#include "go-signal.h"
#include "go-string.h"
#include "runtime.h"
#include "malloc.h"
#undef int
#undef char
#undef unsigned
/* The main function for a Go program. This records the command line
parameters, calls the real main function, and returns a zero status
if the real main function returns. */
extern char **environ;
extern struct __go_open_array Args asm ("libgo_os.os.Args");
extern struct __go_open_array Envs asm ("libgo_os.os.Envs");
/* These functions are created for the main package. */
extern void __go_init_main (void);
extern void real_main (void) asm ("main.main");
/* The main function. */
int
main (int argc, char **argv)
{
int i;
struct __go_string *values;
runtime_mallocinit ();
__go_gc_goroutine_init (&argc);
Args.__count = argc;
Args.__capacity = argc;
values = __go_alloc (argc * sizeof (struct __go_string));
for (i = 0; i < argc; ++i)
{
values[i].__data = (unsigned char *) argv[i];
values[i].__length = __builtin_strlen (argv[i]);
}
Args.__values = values;
for (i = 0; environ[i] != NULL; ++i)
;
Envs.__count = i;
Envs.__capacity = i;
values = __go_alloc (i * sizeof (struct __go_string));
for (i = 0; environ[i] != NULL; ++i)
{
values[i].__data = (unsigned char *) environ[i];
values[i].__length = __builtin_strlen (environ[i]);
}
Envs.__values = values;
__initsig ();
#if defined(HAVE_SRANDOM)
srandom ((unsigned int) time (NULL));
#else
srand ((unsigned int) time (NULL));
#endif
__go_init_main ();
__go_enable_gc ();
real_main ();
return 0;
}
|