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