file_unix.go

 1//go:build unix && !tinygo
 2
 3package sysfs
 4
 5import (
 6	"syscall"
 7
 8	"github.com/tetratelabs/wazero/experimental/sys"
 9)
10
11const (
12	nonBlockingFileReadSupported  = true
13	nonBlockingFileWriteSupported = true
14)
15
16func rmdir(path string) sys.Errno {
17	err := syscall.Rmdir(path)
18	return sys.UnwrapOSError(err)
19}
20
21// readFd exposes syscall.Read.
22func readFd(fd uintptr, buf []byte) (int, sys.Errno) {
23	if len(buf) == 0 {
24		return 0, 0 // Short-circuit 0-len reads.
25	}
26	n, err := syscall.Read(int(fd), buf)
27	errno := sys.UnwrapOSError(err)
28	return n, errno
29}
30
31// writeFd exposes syscall.Write.
32func writeFd(fd uintptr, buf []byte) (int, sys.Errno) {
33	if len(buf) == 0 {
34		return 0, 0 // Short-circuit 0-len writes.
35	}
36	n, err := syscall.Write(int(fd), buf)
37	errno := sys.UnwrapOSError(err)
38	return n, errno
39}