mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-08 21:13:39 +00:00
os: stub out support for some more features
This is necessary for the following: - to make sure os/exec can be imported - to make sure internal/testenv can be imported The internal/testenv package (which imports os/exec) is used by a lot of tests. By adding support for it, more tests can be run. This commit adds a bunch of new packages that now pass all tests.
This commit is contained in:
committed by
Ron Evans
parent
6cbaed75c8
commit
718746dd21
@@ -81,6 +81,12 @@ func Kill(pid int, sig Signal) (err error) {
|
||||
return ENOSYS // TODO
|
||||
}
|
||||
|
||||
type SysProcAttr struct{}
|
||||
|
||||
func Pipe2(p []int, flags int) (err error) {
|
||||
return ENOSYS // TODO
|
||||
}
|
||||
|
||||
func Getenv(key string) (value string, found bool) {
|
||||
data := cstring(key)
|
||||
raw := libc_getenv(&data[0])
|
||||
@@ -115,6 +121,26 @@ func Mprotect(b []byte, prot int) (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func Environ() []string {
|
||||
environ := libc_environ
|
||||
var envs []string
|
||||
for *environ != nil {
|
||||
// Convert the C string to a Go string.
|
||||
length := libc_strlen(*environ)
|
||||
var envVar string
|
||||
rawEnvVar := (*struct {
|
||||
ptr unsafe.Pointer
|
||||
length uintptr
|
||||
})(unsafe.Pointer(&envVar))
|
||||
rawEnvVar.ptr = *environ
|
||||
rawEnvVar.length = length
|
||||
envs = append(envs, envVar)
|
||||
// This is the Go equivalent of "environ++" in C.
|
||||
environ = (*unsafe.Pointer)(unsafe.Pointer(uintptr(unsafe.Pointer(environ)) + unsafe.Sizeof(environ)))
|
||||
}
|
||||
return envs
|
||||
}
|
||||
|
||||
// cstring converts a Go string to a C string.
|
||||
func cstring(s string) []byte {
|
||||
data := make([]byte, len(s)+1)
|
||||
@@ -128,6 +154,9 @@ func splitSlice(p []byte) (buf *byte, len uintptr) {
|
||||
return slice.buf, slice.len
|
||||
}
|
||||
|
||||
//export strlen
|
||||
func libc_strlen(ptr unsafe.Pointer) uintptr
|
||||
|
||||
// ssize_t write(int fd, const void *buf, size_t count)
|
||||
//export write
|
||||
func libc_write(fd int32, buf *byte, count uint) int
|
||||
@@ -167,3 +196,6 @@ func libc_rmdir(pathname *byte) int32
|
||||
// int unlink(const char *pathname);
|
||||
//export unlink
|
||||
func libc_unlink(pathname *byte) int32
|
||||
|
||||
//go:extern environ
|
||||
var libc_environ *unsafe.Pointer
|
||||
|
||||
Reference in New Issue
Block a user