libcall_linux_utimesnano.go 972 B

1234567891011121314151617181920212223242526272829303132
  1. // Copyright 2012 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. //go:build linux
  5. // +build linux
  6. // GNU/Linux version of UtimesNano.
  7. package syscall
  8. import "unsafe"
  9. //sys utimensat(dirfd int, path string, times *[2]Timespec, flags int) (err error)
  10. //utimensat(dirfd _C_int, path *byte, times *[2]Timespec, flags _C_int) _C_int
  11. func UtimesNano(path string, ts []Timespec) (err error) {
  12. if len(ts) != 2 {
  13. return EINVAL
  14. }
  15. err = utimensat(_AT_FDCWD, path, (*[2]Timespec)(unsafe.Pointer(&ts[0])), 0)
  16. if err != ENOSYS {
  17. return err
  18. }
  19. // If the utimensat syscall isn't available (utimensat was added to Linux
  20. // in 2.6.22, Released, 8 July 2007) then fall back to utimes
  21. var tv [2]Timeval
  22. for i := 0; i < 2; i++ {
  23. tv[i].Sec = Timeval_sec_t(ts[i].Sec)
  24. tv[i].Usec = Timeval_usec_t(ts[i].Nsec / 1000)
  25. }
  26. return utimes(path, (*[2]Timeval)(unsafe.Pointer(&tv[0])))
  27. }