github.com/wasilibs/wazerox@v0.0.0-20240124024944-4923be63ab5f/sys/stat_bsd.go (about)

     1  //go:build (amd64 || arm64) && (darwin || freebsd)
     2  
     3  package sys
     4  
     5  import (
     6  	"io/fs"
     7  	"syscall"
     8  )
     9  
    10  const sysParseable = true
    11  
    12  func statFromFileInfo(info fs.FileInfo) Stat_t {
    13  	if d, ok := info.Sys().(*syscall.Stat_t); ok {
    14  		st := Stat_t{}
    15  		st.Dev = uint64(d.Dev)
    16  		st.Ino = d.Ino
    17  		st.Mode = info.Mode()
    18  		st.Nlink = uint64(d.Nlink)
    19  		st.Size = d.Size
    20  		atime := d.Atimespec
    21  		st.Atim = atime.Sec*1e9 + atime.Nsec
    22  		mtime := d.Mtimespec
    23  		st.Mtim = mtime.Sec*1e9 + mtime.Nsec
    24  		ctime := d.Ctimespec
    25  		st.Ctim = ctime.Sec*1e9 + ctime.Nsec
    26  		return st
    27  	}
    28  	return defaultStatFromFileInfo(info)
    29  }