github.com/bananabytelabs/wazero@v0.0.0-20240105073314-54b22a776da8/internal/sysfs/stat_linux.go (about)

     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  
     6  package sysfs
     7  
     8  import (
     9  	"io/fs"
    10  	"os"
    11  
    12  	experimentalsys "github.com/bananabytelabs/wazero/experimental/sys"
    13  	"github.com/bananabytelabs/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
    20  const dirNlinkIncludesDot = true
    21  
    22  func 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  
    30  func 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  
    38  func statFile(f fs.File) (sys.Stat_t, experimentalsys.Errno) {
    39  	return defaultStatFile(f)
    40  }