Files
wazero/internal/platform/stat_bsd.go
Crypt Keeper c46a6eb4ae sysfs: return st instead of accepting it (#1261)
This returns stat as a value instead of a pointer param. This is both
more efficient and faster. It is also more efficient than returning a
pointer to a stat.

Signed-off-by: Adrian Cole <adrian@tetrate.io>
2023-03-21 10:57:19 +08:00

58 lines
1.1 KiB
Go

//go:build (amd64 || arm64) && (darwin || freebsd)
package platform
import (
"io/fs"
"os"
"syscall"
)
func lstat(path string) (Stat_t, error) {
if t, err := os.Lstat(path); err != nil {
return Stat_t{}, err
} else {
return statFromFileInfo(t), nil
}
}
func stat(path string) (Stat_t, error) {
if t, err := os.Stat(path); err != nil {
return Stat_t{}, err
} else {
return statFromFileInfo(t), nil
}
}
func statFile(f fs.File) (Stat_t, error) {
return defaultStatFile(f)
}
func inoFromFileInfo(_ readdirFile, t fs.FileInfo) (ino uint64, err error) {
if d, ok := t.Sys().(*syscall.Stat_t); ok {
ino = d.Ino
}
return
}
func statFromFileInfo(t fs.FileInfo) Stat_t {
if d, ok := t.Sys().(*syscall.Stat_t); ok {
st := Stat_t{}
st.Dev = uint64(d.Dev)
st.Ino = d.Ino
st.Uid = d.Uid
st.Gid = d.Gid
st.Mode = t.Mode()
st.Nlink = uint64(d.Nlink)
st.Size = d.Size
atime := d.Atimespec
st.Atim = atime.Sec*1e9 + atime.Nsec
mtime := d.Mtimespec
st.Mtim = mtime.Sec*1e9 + mtime.Nsec
ctime := d.Ctimespec
st.Ctim = ctime.Sec*1e9 + ctime.Nsec
return st
}
return statFromDefaultFileInfo(t)
}