mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-08 05:27:14 +09:00
LibCore: Simplify System::open
_O_OBTAIN_DIR flag makes _open use FILE_FLAG_BACKUP_SEMANTICS in CreateFile call. FILE_FLAG_BACKUP_SEMANTICS is required to open directory handles. For ordinary files FILE_FLAG_BACKUP_SEMANTICS overrides file security checks when the process has SE_BACKUP_NAME and SE_RESTORE_NAME privileges, see https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createfilea
This commit is contained in:
parent
870cce9d11
commit
259cd70c1b
Notes:
github-actions[bot]
2025-02-06 02:28:51 +00:00
Author: https://github.com/stasoid
Commit: 259cd70c1b
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/3166
Reviewed-by: https://github.com/ADKaster ✅
Reviewed-by: https://github.com/gmta
1 changed files with 4 additions and 17 deletions
|
@ -21,23 +21,10 @@ namespace Core::System {
|
|||
|
||||
ErrorOr<int> open(StringView path, int options, mode_t mode)
|
||||
{
|
||||
ByteString string_path = path;
|
||||
auto sz_path = string_path.characters();
|
||||
int rc = _open(sz_path, options | O_BINARY, mode);
|
||||
if (rc < 0) {
|
||||
int error = errno;
|
||||
struct stat st = {};
|
||||
if (::stat(sz_path, &st) == 0 && (st.st_mode & S_IFDIR)) {
|
||||
HANDLE dir_handle = CreateFile(sz_path, GENERIC_ALL, 0, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);
|
||||
if (dir_handle == INVALID_HANDLE_VALUE)
|
||||
return Error::from_windows_error();
|
||||
int dir_fd = _open_osfhandle((intptr_t)dir_handle, 0);
|
||||
if (dir_fd != -1)
|
||||
return dir_fd;
|
||||
}
|
||||
return Error::from_syscall("open"sv, -error);
|
||||
}
|
||||
return rc;
|
||||
int fd = _open(ByteString(path).characters(), options | O_BINARY | _O_OBTAIN_DIR, mode);
|
||||
if (fd < 0)
|
||||
return Error::from_syscall("open"sv, -errno);
|
||||
return fd;
|
||||
}
|
||||
|
||||
ErrorOr<void> close(int fd)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue