Added utime.h (#188)

* Added utime.h

* Changes after code review

* Auto-generated expected files instead of manually editing
* Fix libpreopoen stat and utime not following symlinks correctly
This commit is contained in:
Olaf Tomalka 2020-04-04 00:39:43 +02:00 committed by GitHub
parent 156fdc476a
commit 7b92f334e6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 23 additions and 3 deletions

View File

@ -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.

View File

@ -1028,6 +1028,7 @@ unlinkat
unsetenv
uselocale
usleep
utime
utimensat
vasprintf
vdprintf

View File

@ -164,6 +164,7 @@
#include <time.h>
#include <uchar.h>
#include <unistd.h>
#include <utime.h>
#include <values.h>
#include <wasi/api.h>
#include <wasi/libc-environ.h>

View File

@ -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

View 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