github.com/mattn/go@v0.0.0-20171011075504-07f7db3ea99f/src/os/stat_solaris.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 package os 6 7 import ( 8 "syscall" 9 "time" 10 ) 11 12 func fillFileStatFromSys(fs *fileStat, name string) { 13 fs.name = basename(name) 14 fs.size = fs.sys.Size 15 fs.modTime = timespecToTime(fs.sys.Mtim) 16 fs.mode = FileMode(fs.sys.Mode & 0777) 17 switch fs.sys.Mode & syscall.S_IFMT { 18 case syscall.S_IFBLK: 19 fs.mode |= ModeDevice 20 case syscall.S_IFCHR: 21 fs.mode |= ModeDevice | ModeCharDevice 22 case syscall.S_IFDIR: 23 fs.mode |= ModeDir 24 case syscall.S_IFIFO: 25 fs.mode |= ModeNamedPipe 26 case syscall.S_IFLNK: 27 fs.mode |= ModeSymlink 28 case syscall.S_IFREG: 29 // nothing to do 30 case syscall.S_IFSOCK: 31 fs.mode |= ModeSocket 32 } 33 if fs.sys.Mode&syscall.S_ISGID != 0 { 34 fs.mode |= ModeSetgid 35 } 36 if fs.sys.Mode&syscall.S_ISUID != 0 { 37 fs.mode |= ModeSetuid 38 } 39 if fs.sys.Mode&syscall.S_ISVTX != 0 { 40 fs.mode |= ModeSticky 41 } 42 } 43 44 func timespecToTime(ts syscall.Timespec) time.Time { 45 return time.Unix(ts.Sec, ts.Nsec) 46 } 47 48 // For testing. 49 func atime(fi FileInfo) time.Time { 50 return timespecToTime(fi.Sys().(*syscall.Stat_t).Atim) 51 }