mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-21 23:20:20 +00:00
LibCore/System: Add mkdir, openat (stub), fstatat (stub) for Windows
Also support directories in open().
This commit is contained in:
parent
f09ed59351
commit
77d205571d
Notes:
github-actions[bot]
2024-11-20 05:08:21 +00:00
Author: https://github.com/stasoid Commit: https://github.com/LadybirdBrowser/ladybird/commit/77d205571d2 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/2188 Reviewed-by: https://github.com/ADKaster ✅
1 changed files with 37 additions and 4 deletions
|
@ -12,7 +12,8 @@
|
|||
#include <AK/ByteString.h>
|
||||
#include <AK/ScopeGuard.h>
|
||||
#include <LibCore/System.h>
|
||||
#include <WinSock2.h>
|
||||
#include <Windows.h>
|
||||
#include <direct.h>
|
||||
#include <io.h>
|
||||
|
||||
namespace Core::System {
|
||||
|
@ -20,9 +21,21 @@ namespace Core::System {
|
|||
ErrorOr<int> open(StringView path, int options, mode_t mode)
|
||||
{
|
||||
ByteString string_path = path;
|
||||
int rc = _open(string_path.characters(), options, mode);
|
||||
if (rc < 0)
|
||||
return Error::from_syscall("open"sv, -errno);
|
||||
auto sz_path = string_path.characters();
|
||||
int rc = _open(sz_path, options, 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(GetLastError());
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -133,4 +146,24 @@ ErrorOr<void> unlink(StringView path)
|
|||
return {};
|
||||
}
|
||||
|
||||
ErrorOr<void> mkdir(StringView path, mode_t)
|
||||
{
|
||||
ByteString str = path;
|
||||
if (_mkdir(str.characters()) < 0)
|
||||
return Error::from_syscall("mkdir"sv, -errno);
|
||||
return {};
|
||||
}
|
||||
|
||||
ErrorOr<int> openat(int, StringView, int, mode_t)
|
||||
{
|
||||
dbgln("Core::System::openat() is not implemented");
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
|
||||
ErrorOr<struct stat> fstatat(int, StringView, int)
|
||||
{
|
||||
dbgln("Core::System::fstatat() is not implemented");
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue