github.com/bananabytelabs/wazero@v0.0.0-20240105073314-54b22a776da8/sys/stat_example_test.go (about) 1 package sys_test 2 3 import ( 4 "io/fs" 5 "math" 6 7 "github.com/bananabytelabs/wazero/sys" 8 ) 9 10 var ( 11 walltime sys.Walltime 12 info fs.FileInfo 13 st sys.Stat_t 14 ) 15 16 // This shows typical conversions to sys.EpochNanos type, for sys.Stat_t fields. 17 func Example_epochNanos() { 18 // Convert an adapted fs.File's fs.FileInfo to Mtim. 19 st.Mtim = info.ModTime().UnixNano() 20 21 // Generate a fake Atim using sys.Walltime passed to wazero.ModuleConfig. 22 sec, nsec := walltime() 23 st.Atim = sec*1e9 + int64(nsec) 24 } 25 26 type fileInfoWithSys struct { 27 fs.FileInfo 28 st sys.Stat_t 29 } 30 31 func (f *fileInfoWithSys) Sys() any { return &f.st } 32 33 // This shows how to return data not defined in fs.FileInfo, notably sys.Inode. 34 func Example_inode() { 35 st := sys.NewStat_t(info) 36 st.Ino = math.MaxUint64 // arbitrary non-zero value 37 info = &fileInfoWithSys{info, st} 38 }