github.com/tetratelabs/wazero@v1.2.1/internal/sysfs/futimens_linux.go (about)

     1  package sysfs
     2  
     3  import (
     4  	"syscall"
     5  	"unsafe"
     6  	_ "unsafe" // for go:linkname
     7  )
     8  
     9  const (
    10  	_AT_FDCWD               = -0x64
    11  	_AT_SYMLINK_NOFOLLOW    = 0x100
    12  	_UTIME_NOW              = (1 << 30) - 1
    13  	_UTIME_OMIT             = (1 << 30) - 2
    14  	SupportsSymlinkNoFollow = true
    15  )
    16  
    17  func utimens(path string, times *[2]syscall.Timespec, symlinkFollow bool) (err error) {
    18  	var flags int
    19  	if !symlinkFollow {
    20  		flags = _AT_SYMLINK_NOFOLLOW
    21  	}
    22  
    23  	var _p0 *byte
    24  	_p0, err = syscall.BytePtrFromString(path)
    25  	if err != nil {
    26  		return
    27  	}
    28  	return utimensat(_AT_FDCWD, uintptr(unsafe.Pointer(_p0)), times, flags)
    29  }
    30  
    31  // On linux, implement futimens via utimensat with the NUL path.
    32  func futimens(fd uintptr, times *[2]syscall.Timespec) error {
    33  	return utimensat(int(fd), 0 /* NUL */, times, 0)
    34  }
    35  
    36  // utimensat is like syscall.utimensat special-cased to accept a NUL string for the path value.
    37  func utimensat(dirfd int, strPtr uintptr, times *[2]syscall.Timespec, flags int) (err error) {
    38  	_, _, e1 := syscall.Syscall6(syscall.SYS_UTIMENSAT, uintptr(dirfd), strPtr, uintptr(unsafe.Pointer(times)), uintptr(flags), 0, 0)
    39  	if e1 != 0 {
    40  		err = e1
    41  	}
    42  	return
    43  }