stat_linux.go

 1//go:build (amd64 || arm64 || riscv64) && linux
 2
 3// Note: This expression is not the same as compiler support, even if it looks
 4// similar. Platform functions here are used in interpreter mode as well.
 5
 6package sysfs
 7
 8import (
 9	"io/fs"
10	"os"
11
12	experimentalsys "github.com/tetratelabs/wazero/experimental/sys"
13	"github.com/tetratelabs/wazero/sys"
14)
15
16// dirNlinkIncludesDot is true because even though os.File filters out dot
17// entries, the underlying syscall.Stat includes them.
18//
19// Note: this is only used in tests
20const dirNlinkIncludesDot = true
21
22func lstat(path string) (sys.Stat_t, experimentalsys.Errno) {
23	if info, err := os.Lstat(path); err != nil {
24		return sys.Stat_t{}, experimentalsys.UnwrapOSError(err)
25	} else {
26		return sys.NewStat_t(info), 0
27	}
28}
29
30func stat(path string) (sys.Stat_t, experimentalsys.Errno) {
31	if info, err := os.Stat(path); err != nil {
32		return sys.Stat_t{}, experimentalsys.UnwrapOSError(err)
33	} else {
34		return sys.NewStat_t(info), 0
35	}
36}
37
38func statFile(f fs.File) (sys.Stat_t, experimentalsys.Errno) {
39	return defaultStatFile(f)
40}