]> git.proxmox.com Git - wasi-libc.git/blame - libc-bottom-half/cloudlibc/src/libc/sys/stat/futimens.c
Wasi snapshot preview1 (#140)
[wasi-libc.git] / libc-bottom-half / cloudlibc / src / libc / sys / stat / futimens.c
CommitLineData
320054e8
DG
1// Copyright (c) 2015-2016 Nuxi, https://nuxi.nl/
2//
3// SPDX-License-Identifier: BSD-2-Clause
4
5#include <sys/stat.h>
6
446cb3f1 7#include <wasi/api.h>
320054e8
DG
8#include <errno.h>
9
10#include "stat_impl.h"
11
12int futimens(int fd, const struct timespec *times) {
13 // Convert timestamps and extract NOW/OMIT flags.
14#ifdef __wasilibc_unmodified_upstream // fstat
15 __wasi_filestat_t fs;
16 __wasi_fsflags_t flags;
17 if (!utimens_get_timestamps(times, &fs, &flags)) {
18#else
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#endif
24 errno = EINVAL;
25 return -1;
26 }
27
28 // Perform system call.
29#ifdef __wasilibc_unmodified_upstream // fstat
30 __wasi_errno_t error = __wasi_file_stat_fput(fd, &fs, flags);
31#else
32 __wasi_errno_t error = __wasi_fd_filestat_set_times(fd, st_atim, st_mtim, flags);
33#endif
34 if (error != 0) {
35 errno = error;
36 return -1;
37 }
38 return 0;
39}