forked from go-llvm/llgo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
os.go
40 lines (34 loc) · 977 Bytes
/
os.go
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
// Copyright 2012 The llgo Authors.
// Use of this source code is governed by an MIT-style
// license that can be found in the LICENSE file.
package runtime
import "unsafe"
// #llgo name: os.Args
// #llgo linkage: common
var os_Args []string
// #llgo name: syscall.envs
// #llgo linkage: common
var syscall_envs []string
func setosargs(argc int32, argv_ **byte, envp_ **byte) {
os_Args = make([]string, argc)
argv := uintptr(unsafe.Pointer(argv_))
for i := int32(0); i < argc; i++ {
arg := *(**byte)(unsafe.Pointer(argv))
arglen := c_strlen(arg)
str := _string{arg, int(arglen)}
os_Args[i] = *(*string)(unsafe.Pointer(&str))
argv += unsafe.Sizeof(argv)
}
envp := uintptr(unsafe.Pointer(envp_))
for {
env := *(**byte)(unsafe.Pointer(envp))
if env == nil {
break
}
envlen := c_strlen(env)
str_ := _string{env, int(envlen)}
str := *(*string)(unsafe.Pointer(&str_))
syscall_envs = append(syscall_envs, str)
envp += unsafe.Sizeof(envp)
}
}