]> git.proxmox.com Git - wasi-libc.git/blob - libc-top-half/musl/src/stat/futimesat.c
Enable support for `utimes` and `futimesat`.
[wasi-libc.git] / libc-top-half / musl / src / stat / futimesat.c
1 #define _GNU_SOURCE
2 #include <sys/time.h>
3 #include <sys/stat.h>
4 #include <errno.h>
5 #ifdef __wasilibc_unmodified_upstream // WASI has no syscall
6 #include "syscall.h"
7 #endif
8
9 int __futimesat(int dirfd, const char *pathname, const struct timeval times[2])
10 {
11 struct timespec ts[2];
12 if (times) {
13 int i;
14 for (i=0; i<2; i++) {
15 if (times[i].tv_usec >= 1000000ULL)
16 #ifdef __wasilibc_unmodified_upstream // WASI has no syscall
17 return __syscall_ret(-EINVAL);
18 #else
19 errno = EINVAL;
20 return -1;
21 #endif
22 ts[i].tv_sec = times[i].tv_sec;
23 ts[i].tv_nsec = times[i].tv_usec * 1000;
24 }
25 }
26 return utimensat(dirfd, pathname, times ? ts : 0, 0);
27 }
28
29 weak_alias(__futimesat, futimesat);