1 /* go-main.c -- the main function for a Go program.
3 Copyright 2009 The Go Authors. All rights reserved.
4 Use of this source code is governed by a BSD-style
5 license that can be found in the LICENSE file. */
12 #ifdef HAVE_FPU_CONTROL_H
13 #include <fpu_control.h>
18 #include "go-signal.h"
19 #include "go-string.h"
29 /* The main function for a Go program. This records the command line
30 parameters, calls the real main function, and returns a zero status
31 if the real main function returns. */
33 extern char **environ
;
35 extern struct __go_open_array Args
asm ("libgo_os.os.Args");
37 extern struct __go_open_array Envs
asm ("libgo_os.os.Envs");
39 /* These functions are created for the main package. */
40 extern void __go_init_main (void);
41 extern void real_main (void) asm ("main.main");
43 /* The main function. */
46 main (int argc
, char **argv
)
49 struct __go_string
*values
;
51 runtime_mallocinit ();
52 runtime_cpuprofinit ();
53 __go_gc_goroutine_init (&argc
);
56 Args
.__capacity
= argc
;
57 values
= __go_alloc (argc
* sizeof (struct __go_string
));
58 for (i
= 0; i
< argc
; ++i
)
60 values
[i
].__data
= (unsigned char *) argv
[i
];
61 values
[i
].__length
= __builtin_strlen (argv
[i
]);
63 Args
.__values
= values
;
65 for (i
= 0; environ
[i
] != NULL
; ++i
)
69 values
= __go_alloc (i
* sizeof (struct __go_string
));
70 for (i
= 0; environ
[i
] != NULL
; ++i
)
72 values
[i
].__data
= (unsigned char *) environ
[i
];
73 values
[i
].__length
= __builtin_strlen (environ
[i
]);
75 Envs
.__values
= values
;
79 #if defined(HAVE_SRANDOM)
80 srandom ((unsigned int) time (NULL
));
82 srand ((unsigned int) time (NULL
));