From a828a0e158e5756673e9ff5e393dfde7acbc7a85 Mon Sep 17 00:00:00 2001 From: stasoid Date: Sat, 26 Oct 2024 20:05:22 +0500 Subject: [PATCH] LibCore/System: Port getcwd, stat, rmdir, unlink to Windows --- Libraries/LibCore/SystemWindows.cpp | 45 +++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/Libraries/LibCore/SystemWindows.cpp b/Libraries/LibCore/SystemWindows.cpp index 22214fb6ded..e1a8dae9614 100644 --- a/Libraries/LibCore/SystemWindows.cpp +++ b/Libraries/LibCore/SystemWindows.cpp @@ -88,4 +88,49 @@ ErrorOr ioctl(int, unsigned, ...) VERIFY_NOT_REACHED(); } +ErrorOr getcwd() +{ + auto* cwd = _getcwd(nullptr, 0); + if (!cwd) + return Error::from_syscall("getcwd"sv, -errno); + + ByteString string_cwd(cwd); + free(cwd); + return string_cwd; +} + +ErrorOr stat(StringView path) +{ + if (path.is_null()) + return Error::from_syscall("stat"sv, -EFAULT); + + struct stat st = {}; + ByteString path_string = path; + if (::stat(path_string.characters(), &st) < 0) + return Error::from_syscall("stat"sv, -errno); + return st; +} + +ErrorOr rmdir(StringView path) +{ + if (path.is_null()) + return Error::from_errno(EFAULT); + + ByteString path_string = path; + if (_rmdir(path_string.characters()) < 0) + return Error::from_syscall("rmdir"sv, -errno); + return {}; +} + +ErrorOr unlink(StringView path) +{ + if (path.is_null()) + return Error::from_errno(EFAULT); + + ByteString path_string = path; + if (_unlink(path_string.characters()) < 0) + return Error::from_syscall("unlink"sv, -errno); + return {}; +} + }