Support dirfd relative iops on Windows

We always favor calling functions like openat(), fstatat(), etc. because
Linux, XNU, FreeBSD, and OpenBSD all elected to support them, while some
systems like Android love them so much, that they stopped supporting the
old interfaces.

This change ensures that when dirfd is actually a dirfd and not AT_FDCWD
we'll do the right thing on Windows NT. We use an API that's been around
since Vista to accomplish that.

This change also adds exponential backoff to chdir() on Windows since it
seems almost as flaky on Windows 7 as the rmdir() function.
This commit is contained in:
Justine Tunney 2021-01-30 01:49:43 -08:00
parent b8d26e2418
commit 417797d218
42 changed files with 361 additions and 241 deletions

View file

@ -25,12 +25,13 @@
/**
* Checks if effective user can access path in particular ways.
*
* @param dirfd is usually AT_FDCWD
* @param dirfd is normally AT_FDCWD but if it's an open directory and
* file is a relative path, then file is opened relative to dirfd
* @param path is a filename or directory
* @param flags can be R_OK, W_OK, X_OK, F_OK
* @param mode can be R_OK, W_OK, X_OK, F_OK
* @param flags should be 0
* @return 0 if ok, or -1 and sets errno
* @asyncsignalsafe
* @syscall
*/
int faccessat(int dirfd, const char *path, int mode, uint32_t flags) {
if (!path) return efault();