libcall_posix_utimesnano.go 789 B

1234567891011121314151617181920212223242526
  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. // +build aix darwin dragonfly freebsd hurd openbsd netbsd solaris
  5. // General POSIX version of UtimesNano.
  6. package syscall
  7. import "unsafe"
  8. func UtimesNano(path string, ts []Timespec) error {
  9. // TODO: The BSDs can do utimensat with SYS_UTIMENSAT but it
  10. // isn't supported by darwin so this uses utimes instead
  11. if len(ts) != 2 {
  12. return EINVAL
  13. }
  14. // Not as efficient as it could be because Timespec and
  15. // Timeval have different types in the different OSes
  16. tv := [2]Timeval{
  17. NsecToTimeval(TimespecToNsec(ts[0])),
  18. NsecToTimeval(TimespecToNsec(ts[1])),
  19. }
  20. return utimes(path, (*[2]Timeval)(unsafe.Pointer(&tv[0])))
  21. }