libluna: Add Result<void>::from_syscall
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
apio 2023-04-18 18:49:24 +02:00
parent 67e9543675
commit 8560918931
Signed by: asleepymoon
GPG Key ID: B8A7D06E42258954
2 changed files with 10 additions and 12 deletions

View File

@ -199,6 +199,13 @@ template <> class Result<void>
return *this;
}
static Result<void> from_syscall(long rc)
{
if (rc < 0) return Error { -rc };
return {};
}
bool has_error() const
{
return m_has_error;

View File

@ -32,21 +32,15 @@ namespace os::FileSystem
Result<void> create_directory(StringView path, mode_t mode)
{
long rc = syscall(SYS_mkdir, path.chars(), mode);
int _ignore = TRY(Result<int>::from_syscall(rc));
ignore(_ignore);
return {};
return Result<void>::from_syscall(rc);
}
Result<void> remove(StringView path)
{
long rc = syscall(SYS_unlink, path.chars(), 0);
int _ignore = TRY(Result<int>::from_syscall(rc));
ignore(_ignore);
return {};
return Result<void>::from_syscall(rc);
}
Result<String> working_directory()
@ -70,10 +64,7 @@ namespace os::FileSystem
Result<void> change_directory(StringView path)
{
long rc = syscall(SYS_chdir, path.chars());
int _ignore = TRY(Result<int>::from_syscall(rc));
ignore(_ignore);
return {};
return Result<void>::from_syscall(rc);
}
}