2015-07-29 14:25:56 -04:00
|
|
|
package system
|
|
|
|
|
|
|
|
import (
|
|
|
|
"syscall"
|
|
|
|
)
|
|
|
|
|
|
|
|
// fromStatT converts a syscall.Stat_t type to a system.Stat_t type
|
2015-07-28 12:13:12 -04:00
|
|
|
func fromStatT(s *syscall.Stat_t) (*StatT, error) {
|
|
|
|
return &StatT{size: s.Size,
|
2015-07-29 14:25:56 -04:00
|
|
|
mode: uint32(s.Mode),
|
|
|
|
uid: s.Uid,
|
|
|
|
gid: s.Gid,
|
|
|
|
rdev: uint64(s.Rdev),
|
|
|
|
mtim: s.Mtimespec}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Stat takes a path to a file and returns
|
|
|
|
// a system.Stat_t type pertaining to that file.
|
|
|
|
//
|
|
|
|
// Throws an error if the file does not exist
|
2015-07-28 12:13:12 -04:00
|
|
|
func Stat(path string) (*StatT, error) {
|
2015-07-29 14:25:56 -04:00
|
|
|
s := &syscall.Stat_t{}
|
|
|
|
if err := syscall.Stat(path, s); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return fromStatT(s)
|
|
|
|
}
|