github.com/bananabytelabs/wazero@v0.0.0-20240105073314-54b22a776da8/internal/sysfs/futimens.go (about) 1 //go:build linux || darwin 2 3 package sysfs 4 5 import ( 6 "syscall" 7 "unsafe" 8 9 "github.com/bananabytelabs/wazero/experimental/sys" 10 ) 11 12 func timesToPtr(times *[2]syscall.Timespec) unsafe.Pointer { //nolint:unused 13 if times != nil { 14 return unsafe.Pointer(×[0]) 15 } 16 return unsafe.Pointer(nil) 17 } 18 19 func 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 }