Skip to content

Commit

Permalink
LibCore/System: Port getcwd, stat, rmdir, unlink to Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
stasoid authored and ADKaster committed Nov 19, 2024
1 parent 4b4a699 commit a828a0e
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions Libraries/LibCore/SystemWindows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,49 @@ ErrorOr<void> ioctl(int, unsigned, ...)
VERIFY_NOT_REACHED();
}

ErrorOr<ByteString> 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<struct stat> 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<void> 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<void> 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 {};
}

}

0 comments on commit a828a0e

Please sign in to comment.