github.com/tetratelabs/wazero@v1.7.3-0.20240513003603-48f702e154b5/internal/sysfs/file_unix.go (about) 1 //go:build unix && !tinygo 2 3 package sysfs 4 5 import ( 6 "syscall" 7 8 "github.com/tetratelabs/wazero/experimental/sys" 9 ) 10 11 const ( 12 nonBlockingFileReadSupported = true 13 nonBlockingFileWriteSupported = true 14 ) 15 16 func rmdir(path string) sys.Errno { 17 err := syscall.Rmdir(path) 18 return sys.UnwrapOSError(err) 19 } 20 21 // readFd exposes syscall.Read. 22 func 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. 32 func 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 }