stat_darwin.go 724 B

1234567891011121314151617181920212223242526272829303132
  1. package system
  2. import (
  3. "syscall"
  4. )
  5. // fromStatT creates a system.StatT type from a syscall.Stat_t type
  6. func fromStatT(s *syscall.Stat_t) (*StatT, error) {
  7. return &StatT{size: s.Size,
  8. mode: uint32(s.Mode),
  9. uid: s.Uid,
  10. gid: s.Gid,
  11. rdev: uint64(s.Rdev),
  12. mtim: s.Mtimespec}, nil
  13. }
  14. // FromStatT loads a system.StatT from a syscall.Stat_t.
  15. func FromStatT(s *syscall.Stat_t) (*StatT, error) {
  16. return fromStatT(s)
  17. }
  18. // Stat takes a path to a file and returns
  19. // a system.StatT type pertaining to that file.
  20. //
  21. // Throws an error if the file does not exist
  22. func Stat(path string) (*StatT, error) {
  23. s := &syscall.Stat_t{}
  24. if err := syscall.Stat(path, s); err != nil {
  25. return nil, err
  26. }
  27. return fromStatT(s)
  28. }