github.com/tetratelabs/wazero@v1.7.3-0.20240513003603-48f702e154b5/internal/sysfs/futimens_darwin.go (about) 1 package sysfs 2 3 import ( 4 "syscall" 5 _ "unsafe" 6 7 experimentalsys "github.com/tetratelabs/wazero/experimental/sys" 8 ) 9 10 const ( 11 _AT_FDCWD = -0x2 12 _AT_SYMLINK_NOFOLLOW = 0x0020 13 _UTIME_OMIT = -2 14 ) 15 16 //go:noescape 17 //go:linkname utimensat syscall.utimensat 18 func utimensat(dirfd int, path string, times *[2]syscall.Timespec, flags int) error 19 20 func utimens(path string, atim, mtim int64) experimentalsys.Errno { 21 times := timesToTimespecs(atim, mtim) 22 if times == nil { 23 return 0 24 } 25 var flags int 26 return experimentalsys.UnwrapOSError(utimensat(_AT_FDCWD, path, times, flags)) 27 } 28 29 func futimens(fd uintptr, atim, mtim int64) experimentalsys.Errno { 30 times := timesToTimespecs(atim, mtim) 31 if times == nil { 32 return 0 33 } 34 _p0 := timesToPtr(times) 35 36 // Warning: futimens only exists since High Sierra (10.13). 37 _, _, e1 := syscall_syscall6(libc_futimens_trampoline_addr, fd, uintptr(_p0), 0, 0, 0, 0) 38 return experimentalsys.UnwrapOSError(e1) 39 } 40 41 // libc_futimens_trampoline_addr is the address of the 42 // `libc_futimens_trampoline` symbol, defined in `futimens_darwin.s`. 43 // 44 // We use this to invoke the syscall through syscall_syscall6 imported below. 45 var libc_futimens_trampoline_addr uintptr 46 47 // Imports the futimens symbol from libc as `libc_futimens`. 48 // 49 // Note: CGO mechanisms are used in darwin regardless of the CGO_ENABLED value 50 // or the "cgo" build flag. See /RATIONALE.md for why. 51 //go:cgo_import_dynamic libc_futimens futimens "/usr/lib/libSystem.B.dylib"