utimes_wasip1.mx raw
1 // Copyright 2025 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4
5 //go:build wasip1
6
7 package unix
8
9 import (
10 "syscall"
11 "unsafe"
12 )
13
14 //go:wasmimport wasi_snapshot_preview1 path_filestat_set_times
15 //go:noescape
16 func path_filestat_set_times(fd int32, flags uint32, path *byte, pathLen size, atim uint64, mtim uint64, fstflags uint32) syscall.Errno
17
18 func Utimensat(dirfd int, path string, times *[2]syscall.Timespec, flag int) error {
19 if path == "" {
20 return syscall.EINVAL
21 }
22 atime := syscall.TimespecToNsec(times[0])
23 mtime := syscall.TimespecToNsec(times[1])
24
25 var fflag uint32
26 if times[0].Nsec != UTIME_OMIT {
27 fflag |= syscall.FILESTAT_SET_ATIM
28 }
29 if times[1].Nsec != UTIME_OMIT {
30 fflag |= syscall.FILESTAT_SET_MTIM
31 }
32 errno := path_filestat_set_times(
33 int32(dirfd),
34 syscall.LOOKUP_SYMLINK_FOLLOW,
35 unsafe.StringData(path),
36 size(len(path)),
37 uint64(atime),
38 uint64(mtime),
39 fflag,
40 )
41 return errnoErr(errno)
42 }
43