mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-06-27 14:58:30 +00:00
Make improvements
- Invent openatemp() API - Invent O_UNLINK open flag - Introduce getenv_secure() API - Remove `git pull` from cosmocc - Fix utimes() when path is NULL - Fix mktemp() to never return NULL - Fix utimensat() UTIME_OMIT on XNU - Improve utimensat() code for RHEL5 - Turn `argv[0]` C:/ to /C/ on Windows - Introduce tmpnam() and tmpnam_r() APIs - Fix more const issues with internal APIs - Permit utimes() on WIN32 in O_RDONLY mode - Fix fdopendir() to check fd is a directory - Fix recent crash regression in landlock make - Fix futimens(AT_FDCWD, NULL) to return EBADF - Use workaround so `make -j` doesn't fork bomb - Rename dontdiscard to __wur (just like glibc) - Fix st_size for WIN32 symlinks containing UTF-8 - Introduce stdio ext APIs needed by GNU coreutils - Fix lstat() on WIN32 for symlinks to directories - Move some constants from normalize.inc to limits.h - Fix segv with memchr() and memcmp() overlapping page - Implement POSIX fflush() behavior for reader streams - Implement AT_SYMLINK_NOFOLLOW for utimensat() on WIN32 - Don't change read-only status of existing files on WIN32 - Correctly handle `0x[^[:xdigit:]]` case in strtol() functions
This commit is contained in:
parent
8596e83cce
commit
f531acc8f9
297 changed files with 1920 additions and 1681 deletions
|
@ -23,14 +23,17 @@
|
|||
#include "libc/calls/syscall-nt.internal.h"
|
||||
#include "libc/calls/syscall_support-nt.internal.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/intrin/kprintf.h"
|
||||
#include "libc/macros.internal.h"
|
||||
#include "libc/nt/createfile.h"
|
||||
#include "libc/nt/enum/accessmask.h"
|
||||
#include "libc/nt/enum/creationdisposition.h"
|
||||
#include "libc/nt/enum/fileflagandattributes.h"
|
||||
#include "libc/nt/enum/filesharemode.h"
|
||||
#include "libc/nt/enum/filetype.h"
|
||||
#include "libc/nt/files.h"
|
||||
#include "libc/nt/process.h"
|
||||
#include "libc/nt/runtime.h"
|
||||
#include "libc/nt/synchronization.h"
|
||||
#include "libc/nt/thunk/msabi.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/sysv/consts/fileno.h"
|
||||
|
@ -98,6 +101,16 @@ static textwindows int64_t sys_open_nt_impl(int dirfd, const char *path,
|
|||
return kNtInvalidHandleValue;
|
||||
}
|
||||
|
||||
if (fattr != -1u) {
|
||||
// "We have been asked to create a read-only file. "If the file
|
||||
// already exists, the semantics of the Unix open system call is to
|
||||
// preserve the existing permissions. If we pass CREATE_ALWAYS and
|
||||
// FILE_ATTRIBUTE_READONLY to CreateFile, and the file already
|
||||
// exists, CreateFile will change the file permissions. Avoid that to
|
||||
// preserve the Unix semantics." -Quoth GoLang syscall_windows.go
|
||||
attr &= ~kNtFileAttributeReadonly;
|
||||
}
|
||||
|
||||
// kNtTruncateExisting always returns kNtErrorInvalidParameter :'(
|
||||
if (disp == kNtTruncateExisting) {
|
||||
if (fattr != -1u) {
|
||||
|
@ -107,10 +120,24 @@ static textwindows int64_t sys_open_nt_impl(int dirfd, const char *path,
|
|||
}
|
||||
}
|
||||
|
||||
// We optimistically request some write permissions in O_RDONLY mode.
|
||||
// But that might prevent opening some files. So reactively back off.
|
||||
int extra_perm = 0;
|
||||
if ((flags & O_ACCMODE) == O_RDONLY) {
|
||||
extra_perm = kNtFileWriteAttributes | kNtFileWriteEa;
|
||||
}
|
||||
|
||||
// open the file, following symlinks
|
||||
return __fix_enotdir(CreateFile(path16, perm, share, &kNtIsInheritable, disp,
|
||||
attr | extra_attr, 0),
|
||||
path16);
|
||||
int e = errno;
|
||||
int64_t hand = CreateFile(path16, perm | extra_perm, share, &kNtIsInheritable,
|
||||
disp, attr | extra_attr, 0);
|
||||
if (hand == -1 && errno == EACCES && (flags & O_ACCMODE) == O_RDONLY) {
|
||||
errno = e;
|
||||
hand = CreateFile(path16, perm, share, &kNtIsInheritable, disp,
|
||||
attr | extra_attr, 0);
|
||||
}
|
||||
|
||||
return __fix_enotdir(hand, path16);
|
||||
}
|
||||
|
||||
static textwindows int sys_open_nt_console(int dirfd,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue