aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/syscall
diff options
context:
space:
mode:
authorDan Kegel <[email protected]>2021-12-31 21:53:20 -0800
committerRon Evans <[email protected]>2022-04-08 08:29:30 +0200
commitc78df850152da88fc77d4724cd98de22027e5c31 (patch)
tree10d84a44acda13da100fd875b2447714aeedfe88 /src/syscall
parentc0d257d68217ae9af36489f2b39a23314f8c4fdc (diff)
downloadtinygo-c78df850152da88fc77d4724cd98de22027e5c31.tar.gz
tinygo-c78df850152da88fc77d4724cd98de22027e5c31.zip
os: Implement Pipe for darwin, add smoke test.
Evidently when you read from pipes in Go, you have to adjust your slice length to reflect the number of bytes read. Verified upstream behaves the same way.
Diffstat (limited to 'src/syscall')
-rw-r--r--src/syscall/syscall_libc.go4
-rw-r--r--src/syscall/syscall_libc_darwin.go17
-rw-r--r--src/syscall/syscall_libc_nintendoswitch.go4
-rw-r--r--src/syscall/syscall_libc_wasi.go4
-rw-r--r--src/syscall/syscall_nonhosted.go3
5 files changed, 28 insertions, 4 deletions
diff --git a/src/syscall/syscall_libc.go b/src/syscall/syscall_libc.go
index bbc54888a..3fa3db043 100644
--- a/src/syscall/syscall_libc.go
+++ b/src/syscall/syscall_libc.go
@@ -153,10 +153,6 @@ func Kill(pid int, sig Signal) (err error) {
type SysProcAttr struct{}
-func Pipe2(p []int, flags int) (err error) {
- return ENOSYS // TODO
-}
-
// TODO
type WaitStatus uint32
diff --git a/src/syscall/syscall_libc_darwin.go b/src/syscall/syscall_libc_darwin.go
index 770e71b58..80acebfc2 100644
--- a/src/syscall/syscall_libc_darwin.go
+++ b/src/syscall/syscall_libc_darwin.go
@@ -246,6 +246,19 @@ func Fdopendir(fd int) (dir uintptr, err error) {
return
}
+func Pipe2(fds []int, flags int) (err error) {
+ // Mac only has Pipe, which ignores the flags argument
+ buf := make([]int32, 2)
+ fail := int(libc_pipe(&buf[0]))
+ if fail < 0 {
+ err = getErrno()
+ } else {
+ fds[0] = int(buf[0])
+ fds[1] = int(buf[1])
+ }
+ return
+}
+
func readdir_r(dir uintptr, entry *Dirent, result **Dirent) (err error) {
e1 := libc_readdir_r(unsafe.Pointer(dir), unsafe.Pointer(entry), unsafe.Pointer(result))
if e1 != 0 {
@@ -278,3 +291,7 @@ func libc_fstat(fd int32, ptr unsafe.Pointer) int32
// int lstat(const char *path, struct stat * buf);
//export lstat$INODE64
func libc_lstat(pathname *byte, ptr unsafe.Pointer) int32
+
+// int pipe(int32 *fds);
+//export pipe
+func libc_pipe(fds *int32) int32
diff --git a/src/syscall/syscall_libc_nintendoswitch.go b/src/syscall/syscall_libc_nintendoswitch.go
index 98494643f..52b739394 100644
--- a/src/syscall/syscall_libc_nintendoswitch.go
+++ b/src/syscall/syscall_libc_nintendoswitch.go
@@ -63,3 +63,7 @@ var libcErrno uintptr
func getErrno() error {
return Errno(libcErrno)
}
+
+func Pipe2(p []int, flags int) (err error) {
+ return ENOSYS // TODO
+}
diff --git a/src/syscall/syscall_libc_wasi.go b/src/syscall/syscall_libc_wasi.go
index 6bfab090f..cf9da47f6 100644
--- a/src/syscall/syscall_libc_wasi.go
+++ b/src/syscall/syscall_libc_wasi.go
@@ -292,6 +292,10 @@ func Lstat(path string, p *Stat_t) (err error) {
return
}
+func Pipe2(p []int, flags int) (err error) {
+ return ENOSYS // TODO
+}
+
// int stat(const char *path, struct stat * buf);
//export stat
func libc_stat(pathname *byte, ptr unsafe.Pointer) int32
diff --git a/src/syscall/syscall_nonhosted.go b/src/syscall/syscall_nonhosted.go
index 4a5585503..3528087f8 100644
--- a/src/syscall/syscall_nonhosted.go
+++ b/src/syscall/syscall_nonhosted.go
@@ -180,6 +180,9 @@ type SysProcAttr struct {
func Getgroups() ([]int, error) { return []int{1}, nil }
func Gettimeofday(tv *Timeval) error { return ENOSYS }
func Kill(pid int, signum Signal) error { return ENOSYS }
+func Pipe2(p []int, flags int) (err error) {
+ return ENOSYS // TODO
+}
func Sendfile(outfd int, infd int, offset *int64, count int) (written int, err error) {
return 0, ENOSYS
}