github.com/wasilibs/wazerox@v0.0.0-20240124024944-4923be63ab5f/internal/sysfs/file_unix.go (about)

     1  //go:build unix
     2  
     3  package sysfs
     4  
     5  import (
     6  	"syscall"
     7  
     8  	"github.com/wasilibs/wazerox/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  }