diff --git a/Makefile b/Makefile index a19507d..48b09b0 100644 --- a/Makefile +++ b/Makefile @@ -316,8 +316,7 @@ MUSL_OMIT_HEADERS += \ "netinet/ether.h" \ "sys/timerfd.h" \ "libintl.h" \ - "sys/sysmacros.h" \ - "utime.h" + "sys/sysmacros.h" ifeq ($(THREAD_MODEL), single) # Remove headers not supported in single-threaded mode. diff --git a/expected/wasm32-wasi/defined-symbols.txt b/expected/wasm32-wasi/defined-symbols.txt index dc20ddf..06bf802 100644 --- a/expected/wasm32-wasi/defined-symbols.txt +++ b/expected/wasm32-wasi/defined-symbols.txt @@ -1028,6 +1028,7 @@ unlinkat unsetenv uselocale usleep +utime utimensat vasprintf vdprintf diff --git a/expected/wasm32-wasi/include-all.c b/expected/wasm32-wasi/include-all.c index 71665bc..e801c08 100644 --- a/expected/wasm32-wasi/include-all.c +++ b/expected/wasm32-wasi/include-all.c @@ -164,6 +164,7 @@ #include #include #include +#include #include #include #include diff --git a/expected/wasm32-wasi/predefined-macros.txt b/expected/wasm32-wasi/predefined-macros.txt index db4ae4d..595f343 100644 --- a/expected/wasm32-wasi/predefined-macros.txt +++ b/expected/wasm32-wasi/predefined-macros.txt @@ -2407,6 +2407,7 @@ #define _TIME_H #define _UCHAR_H #define _UNISTD_H +#define _UTIME_H #define _VALUES_H #define _VA_LIST #define _WCHAR_H diff --git a/libc-bottom-half/libpreopen/libpreopen.c b/libc-bottom-half/libpreopen/libpreopen.c index fd1d6f9..23e0dae 100644 --- a/libc-bottom-half/libpreopen/libpreopen.c +++ b/libc-bottom-half/libpreopen/libpreopen.c @@ -44,6 +44,7 @@ #define _ALL_SOURCE #include +#include #include #include #include @@ -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