Write tests and fixes for utimensat()

This commit is contained in:
Justine Tunney 2022-06-17 02:43:00 -07:00
parent c06ffd458c
commit d0d9cd38c5
8 changed files with 129 additions and 41 deletions

View file

@ -24,25 +24,45 @@
#include "libc/dce.h"
#include "libc/intrin/asan.internal.h"
#include "libc/intrin/describeflags.internal.h"
#include "libc/sysv/consts/at.h"
#include "libc/sysv/errfuns.h"
#include "libc/zipos/zipos.internal.h"
/**
* Sets atime/mtime on file, the modern way.
*
* This is two functions in one. If `path` is null then this function
* becomes the same as `futimens(dirfd, ts)`.
*
* XNU and RHEL5 only have microsecond accuracy and there's no `dirfd`
* relative support.
*
* @param dirfd should AT_FDCWD
* @param ts is atime/mtime, or null for current time
* @param flags can have AT_SYMLINK_NOFOLLOW
* @note no xnu/rhel5 support if dirfdAT_FDCWDflags0
* @raise ENOSYS on RHEL5 if path is NULL
* @raise EINVAL if flags had unrecognized bits
* @raise EINVAL if path is NULL and flags has AT_SYMLINK_NOFOLLOW
* @raise EBADF if dirfd isn't a valid fd or AT_FDCWD
* @raise EFAULT if path or ts memory was invalid
* @raise EROFS if file system is read-only
* @raise ENAMETOOLONG
* @raise EPERM
* @see futimens()
* @asyncsignalsafe
*/
int utimensat(int dirfd, const char *path, const struct timespec ts[2],
int flags) {
int rc;
char buf[12];
if (IsAsan() && (!__asan_is_valid(path, 1) ||
if (IsAsan() && ((dirfd == AT_FDCWD && !__asan_is_valid(path, 1)) ||
(ts && (!__asan_is_valid_timespec(ts + 0) ||
!__asan_is_valid_timespec(ts + 1))))) {
rc = efault();
rc = efault(); // bad memory
} else if ((flags & ~AT_SYMLINK_NOFOLLOW)) {
rc = einval(); // unsupported flag
} else if (!path && flags) {
rc = einval(); // futimens() doesn't take flags
} else if (weaken(__zipos_notat) && (rc = __zipos_notat(dirfd, path)) == -1) {
STRACE("zipos mkdirat not supported yet");
} else if (!IsWindows()) {