mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-06 11:18:30 +00:00
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:
parent
b8d26e2418
commit
417797d218
42 changed files with 361 additions and 241 deletions
|
@ -35,25 +35,12 @@ textwindows int utimensat$nt(int dirfd, const char *path,
|
|||
const struct timespec ts[2], int flags) {
|
||||
int i, rc;
|
||||
int64_t fh;
|
||||
bool closeme;
|
||||
uint16_t path16[PATH_MAX];
|
||||
struct NtFileTime ft[2], *ftp[2];
|
||||
if (flags) return einval();
|
||||
if (path) {
|
||||
if (dirfd == AT_FDCWD) {
|
||||
if (__mkntpath(path, path16) == -1) return -1;
|
||||
if ((fh = CreateFile(path16, kNtFileWriteAttributes, kNtFileShareRead,
|
||||
NULL, kNtOpenExisting, kNtFileAttributeNormal, 0)) !=
|
||||
-1) {
|
||||
closeme = true;
|
||||
} else {
|
||||
return __winerr();
|
||||
}
|
||||
} else {
|
||||
return einval();
|
||||
}
|
||||
} else {
|
||||
return ebadf();
|
||||
if (__mkntpathat(dirfd, path, 0, path16) == -1) return -1;
|
||||
if ((fh = CreateFile(path16, kNtFileWriteAttributes, kNtFileShareRead, NULL,
|
||||
kNtOpenExisting, kNtFileAttributeNormal, 0)) == -1) {
|
||||
return __winerr();
|
||||
}
|
||||
if (!ts || ts[0].tv_nsec == UTIME_NOW || ts[1].tv_nsec == UTIME_NOW) {
|
||||
GetSystemTimeAsFileTime(ft);
|
||||
|
@ -78,8 +65,6 @@ textwindows int utimensat$nt(int dirfd, const char *path,
|
|||
} else {
|
||||
rc = __winerr();
|
||||
}
|
||||
if (closeme) {
|
||||
CloseHandle(fh);
|
||||
}
|
||||
CloseHandle(fh);
|
||||
return rc;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue