Files
wazero/internal/sysfs/futimens_linux.go
Crypt Keeper fb6147ca94
Some checks failed
Release CLI / Pre-release build (push) Has been cancelled
Release CLI / Pre-release test (macos-12) (push) Has been cancelled
Release CLI / Pre-release test (ubuntu-22.04) (push) Has been cancelled
Release CLI / Pre-release test (windows-2022) (push) Has been cancelled
Release CLI / Release (push) Has been cancelled
Emulates AT_SYMLINK_NOFOLLOW instead of sometimes implementing it (#1588)
Signed-off-by: Adrian Cole <adrian@tetrate.io>
2023-07-22 08:03:47 +08:00

38 lines
956 B
Go

package sysfs
import (
"syscall"
"unsafe"
_ "unsafe" // for go:linkname
)
const (
_AT_FDCWD = -0x64
_UTIME_NOW = (1 << 30) - 1
_UTIME_OMIT = (1 << 30) - 2
)
func utimens(path string, times *[2]syscall.Timespec) (err error) {
var flags int
var _p0 *byte
_p0, err = syscall.BytePtrFromString(path)
if err != nil {
return
}
return utimensat(_AT_FDCWD, uintptr(unsafe.Pointer(_p0)), times, flags)
}
// On linux, implement futimens via utimensat with the NUL path.
func futimens(fd uintptr, times *[2]syscall.Timespec) error {
return utimensat(int(fd), 0 /* NUL */, times, 0)
}
// utimensat is like syscall.utimensat special-cased to accept a NUL string for the path value.
func utimensat(dirfd int, strPtr uintptr, times *[2]syscall.Timespec, flags int) (err error) {
_, _, e1 := syscall.Syscall6(syscall.SYS_UTIMENSAT, uintptr(dirfd), strPtr, uintptr(unsafe.Pointer(times)), uintptr(flags), 0, 0)
if e1 != 0 {
err = e1
}
return
}