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