futimens.go

 1//go:build (linux || darwin) && !tinygo
 2
 3package sysfs
 4
 5import (
 6	"syscall"
 7	"unsafe"
 8
 9	"github.com/tetratelabs/wazero/experimental/sys"
10)
11
12func timesToPtr(times *[2]syscall.Timespec) unsafe.Pointer { //nolint:unused
13	if times != nil {
14		return unsafe.Pointer(&times[0])
15	}
16	return unsafe.Pointer(nil)
17}
18
19func timesToTimespecs(atim int64, mtim int64) (times *[2]syscall.Timespec) {
20	// When both inputs are omitted, there is nothing to change.
21	if atim == sys.UTIME_OMIT && mtim == sys.UTIME_OMIT {
22		return
23	}
24
25	times = &[2]syscall.Timespec{}
26	if atim == sys.UTIME_OMIT {
27		times[0] = syscall.Timespec{Nsec: _UTIME_OMIT}
28		times[1] = syscall.NsecToTimespec(mtim)
29	} else if mtim == sys.UTIME_OMIT {
30		times[0] = syscall.NsecToTimespec(atim)
31		times[1] = syscall.Timespec{Nsec: _UTIME_OMIT}
32	} else {
33		times[0] = syscall.NsecToTimespec(atim)
34		times[1] = syscall.NsecToTimespec(mtim)
35	}
36	return
37}