]> git.proxmox.com Git - wasi-libc.git/blobdiff - libc-bottom-half/libpreopen/libpreopen.c
Added utime.h (#188)
[wasi-libc.git] / libc-bottom-half / libpreopen / libpreopen.c
index fd1d6f96090f6a626367ac287114ae50e6174699..23e0daef190f0f0e65b31337e5f62dad17b6e5bf 100644 (file)
@@ -44,6 +44,7 @@
 
 #define _ALL_SOURCE
 #include <sys/stat.h>
+#include <utime.h>
 #include <fcntl.h>
 #include <stdarg.h>
 #include <stdlib.h>
@@ -152,7 +153,24 @@ stat(const char *path, struct stat *st)
         return -1;
     }
 
-    return fstatat(dirfd, relative_path, st, AT_SYMLINK_NOFOLLOW);
+    return fstatat(dirfd, relative_path, st, 0);
+}
+
+int
+utime(const char *path, const struct utimbuf *times)
+{
+    const char *relative_path;
+    int fd = __wasilibc_find_relpath(path, &relative_path);
+
+    // If we can't find a preopened directory handle to open this file with,
+    // indicate that the program lacks the capabilities.
+    if (fd == -1) {
+        errno = ENOTCAPABLE;
+        return -1;
+    }
+    return utimensat(fd, relative_path, times ? ((struct timespec [2]){
+               { .tv_sec = times->actime }, { .tv_sec = times->modtime }})
+        : 0, 0);
 }
 
 int