forked from karelbilek/wazero-fs-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
file_unix.go
39 lines (32 loc) · 785 Bytes
/
file_unix.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
//go:build unix
package sysfs
import (
"syscall"
"github.com/tetratelabs/wazero/experimental/sys"
)
const (
nonBlockingFileReadSupported = true
nonBlockingFileWriteSupported = true
)
func rmdir(path string) sys.Errno {
err := syscall.Rmdir(path)
return sys.UnwrapOSError(err)
}
// readFd exposes syscall.Read.
func readFd(fd uintptr, buf []byte) (int, sys.Errno) {
if len(buf) == 0 {
return 0, 0 // Short-circuit 0-len reads.
}
n, err := syscall.Read(int(fd), buf)
errno := sys.UnwrapOSError(err)
return n, errno
}
// writeFd exposes syscall.Write.
func writeFd(fd uintptr, buf []byte) (int, sys.Errno) {
if len(buf) == 0 {
return 0, 0 // Short-circuit 0-len writes.
}
n, err := syscall.Write(int(fd), buf)
errno := sys.UnwrapOSError(err)
return n, errno
}