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
5// GNU/Linux version of UtimesNano.
6
7package syscall
8
9import "unsafe"
10
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
13func UtimesNano(path string, ts []Timespec) (err error) {
14	if len(ts) != 2 {
15		return EINVAL
16	}
17	err = utimensat(_AT_FDCWD, path, (*[2]Timespec)(unsafe.Pointer(&ts[0])), 0)
18	if err != ENOSYS {
19		return err
20	}
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)
27	}
28	return utimes(path, (*[2]Timeval)(unsafe.Pointer(&tv[0])))
29}
30