github.com/tetratelabs/wazero@v1.7.3-0.20240513003603-48f702e154b5/internal/sysfs/futimens_windows.go (about) 1 package sysfs 2 3 import ( 4 "syscall" 5 6 "github.com/tetratelabs/wazero/experimental/sys" 7 ) 8 9 func utimens(path string, atim, mtim int64) sys.Errno { 10 return chtimes(path, atim, mtim) 11 } 12 13 func futimens(fd uintptr, atim, mtim int64) error { 14 // Per docs, zero isn't a valid timestamp as it cannot be differentiated 15 // from nil. In both cases, it is a marker like sys.UTIME_OMIT. 16 // See https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-setfiletime 17 a, w := timespecToFiletime(atim, mtim) 18 19 if a == nil && w == nil { 20 return nil // both omitted, so nothing to change 21 } 22 23 // Attempt to get the stat by handle, which works for normal files 24 h := syscall.Handle(fd) 25 26 // Note: This returns ERROR_ACCESS_DENIED when the input is a directory. 27 return syscall.SetFileTime(h, nil, a, w) 28 } 29 30 func timespecToFiletime(atim, mtim int64) (a, w *syscall.Filetime) { 31 a = timespecToFileTime(atim) 32 w = timespecToFileTime(mtim) 33 return 34 } 35 36 func timespecToFileTime(tim int64) *syscall.Filetime { 37 if tim == sys.UTIME_OMIT { 38 return nil 39 } 40 ft := syscall.NsecToFiletime(tim) 41 return &ft 42 }