stat_linux.go 574 B

123456789101112131415161718192021222324252627
  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) (*Stat_t, error) {
  7. return &Stat_t{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. // Stat takes a path to a file and returns
  15. // a system.Stat_t type pertaining to that file.
  16. //
  17. // Throws an error if the file does not exist
  18. func Stat(path string) (*Stat_t, error) {
  19. s := &syscall.Stat_t{}
  20. if err := syscall.Stat(path, s); err != nil {
  21. return nil, err
  22. }
  23. return fromStatT(s)
  24. }