github.com/lovishpuri/go-40569/src@v0.0.0-20230519171745-f8623e7c56cf/os/stat_js.go (about) 1 // Copyright 2009 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 //go:build js && wasm 6 7 package os 8 9 import ( 10 "syscall" 11 "time" 12 ) 13 14 func fillFileStatFromSys(fs *fileStat, name string) { 15 fs.name = basename(name) 16 fs.size = fs.sys.Size 17 fs.modTime = time.Unix(fs.sys.Mtime, fs.sys.MtimeNsec) 18 fs.mode = FileMode(fs.sys.Mode & 0777) 19 switch fs.sys.Mode & syscall.S_IFMT { 20 case syscall.S_IFBLK: 21 fs.mode |= ModeDevice 22 case syscall.S_IFCHR: 23 fs.mode |= ModeDevice | ModeCharDevice 24 case syscall.S_IFDIR: 25 fs.mode |= ModeDir 26 case syscall.S_IFIFO: 27 fs.mode |= ModeNamedPipe 28 case syscall.S_IFLNK: 29 fs.mode |= ModeSymlink 30 case syscall.S_IFREG: 31 // nothing to do 32 case syscall.S_IFSOCK: 33 fs.mode |= ModeSocket 34 } 35 if fs.sys.Mode&syscall.S_ISGID != 0 { 36 fs.mode |= ModeSetgid 37 } 38 if fs.sys.Mode&syscall.S_ISUID != 0 { 39 fs.mode |= ModeSetuid 40 } 41 if fs.sys.Mode&syscall.S_ISVTX != 0 { 42 fs.mode |= ModeSticky 43 } 44 } 45 46 // For testing. 47 func atime(fi FileInfo) time.Time { 48 st := fi.Sys().(*syscall.Stat_t) 49 return time.Unix(st.Atime, st.AtimeNsec) 50 }