]> git.proxmox.com Git - wasi-libc.git/blob - libc-bottom-half/cloudlibc/src/libc/sys/stat/utimensat.c
AT_FDCWD support.
[wasi-libc.git] / libc-bottom-half / cloudlibc / src / libc / sys / stat / utimensat.c
1 // Copyright (c) 2015-2016 Nuxi, https://nuxi.nl/
2 //
3 // SPDX-License-Identifier: BSD-2-Clause
4
5 #include <common/errno.h>
6
7 #include <sys/stat.h>
8
9 #include <wasi/api.h>
10 #include <errno.h>
11 #include <fcntl.h>
12 #include <string.h>
13
14 #include "stat_impl.h"
15
16 int __wasilibc_nocwd_utimensat(int fd, const char *path, const struct timespec times[2],
17 int flag) {
18 // Convert timestamps and extract NOW/OMIT flags.
19 __wasi_timestamp_t st_atim;
20 __wasi_timestamp_t st_mtim;
21 __wasi_fstflags_t flags;
22 if (!utimens_get_timestamps(times, &st_atim, &st_mtim, &flags)) {
23 errno = EINVAL;
24 return -1;
25 }
26
27 // Create lookup properties.
28 __wasi_lookupflags_t lookup_flags = 0;
29 if ((flag & AT_SYMLINK_NOFOLLOW) == 0)
30 lookup_flags |= __WASI_LOOKUPFLAGS_SYMLINK_FOLLOW;
31
32 // Perform system call.
33 __wasi_errno_t error =
34 __wasi_path_filestat_set_times(fd, lookup_flags, path, strlen(path), st_atim, st_mtim, flags);
35 if (error != 0) {
36 errno = errno_fixup_directory(fd, error);
37 return -1;
38 }
39 return 0;
40 }