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:
@@ -18,12 +18,22 @@
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/internal.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/sysv/consts/at.h"
|
||||
|
||||
int unlinkat(int dirfd, const char *pathname, int flags) {
|
||||
if (dirfd == AT_FDCWD) {
|
||||
return unlink(pathname);
|
||||
/**
|
||||
* Deletes inode and maybe the file too.
|
||||
*
|
||||
* @param dirfd is normally AT_FDCWD but if it's an open directory and
|
||||
* path is relative, then path becomes relative to dirfd
|
||||
* @param path is the thing to delete
|
||||
* @param flags can have AT_REMOVEDIR
|
||||
* @return 0 on success, or -1 w/ errno
|
||||
*/
|
||||
int unlinkat(int dirfd, const char *path, int flags) {
|
||||
if (!IsWindows()) {
|
||||
return unlinkat$sysv(dirfd, path, flags);
|
||||
} else {
|
||||
return unlinkat$sysv(dirfd, pathname, flags);
|
||||
return unlinkat$nt(dirfd, path, flags);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user