stat_linux.go 731 B

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