github.com/gaukas/wazerofs@v0.1.0/sysfs/futimens_linux.go (about) 1 package sysfs 2 3 import ( 4 "syscall" 5 "unsafe" 6 _ "unsafe" 7 8 experimentalsys "github.com/tetratelabs/wazero/experimental/sys" 9 ) 10 11 const ( 12 _AT_FDCWD = -0x64 13 _UTIME_OMIT = (1 << 30) - 2 14 ) 15 16 func utimens(path string, atim, mtim int64) experimentalsys.Errno { 17 times := timesToTimespecs(atim, mtim) 18 if times == nil { 19 return 0 20 } 21 22 var flags int 23 var _p0 *byte 24 _p0, err := syscall.BytePtrFromString(path) 25 if err == nil { 26 err = utimensat(_AT_FDCWD, uintptr(unsafe.Pointer(_p0)), times, flags) 27 } 28 return experimentalsys.UnwrapOSError(err) 29 } 30 31 // On linux, implement futimens via utimensat with the NUL path. 32 func futimens(fd uintptr, atim, mtim int64) experimentalsys.Errno { 33 times := timesToTimespecs(atim, mtim) 34 if times == nil { 35 return 0 36 } 37 return experimentalsys.UnwrapOSError(utimensat(int(fd), 0 /* NUL */, times, 0)) 38 } 39 40 // utimensat is like syscall.utimensat special-cased to accept a NUL string for the path value. 41 func utimensat(dirfd int, strPtr uintptr, times *[2]syscall.Timespec, flags int) (err error) { 42 _, _, e1 := syscall.Syscall6(syscall.SYS_UTIMENSAT, uintptr(dirfd), strPtr, uintptr(unsafe.Pointer(times)), uintptr(flags), 0, 0) 43 if e1 != 0 { 44 err = e1 45 } 46 return 47 }