libluna: Add Result<void>::from_syscall
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
parent
67e9543675
commit
8560918931
@ -199,6 +199,13 @@ template <> class Result<void>
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Result<void> from_syscall(long rc)
|
||||||
|
{
|
||||||
|
if (rc < 0) return Error { -rc };
|
||||||
|
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
bool has_error() const
|
bool has_error() const
|
||||||
{
|
{
|
||||||
return m_has_error;
|
return m_has_error;
|
||||||
|
@ -32,21 +32,15 @@ namespace os::FileSystem
|
|||||||
Result<void> create_directory(StringView path, mode_t mode)
|
Result<void> create_directory(StringView path, mode_t mode)
|
||||||
{
|
{
|
||||||
long rc = syscall(SYS_mkdir, path.chars(), mode);
|
long rc = syscall(SYS_mkdir, path.chars(), mode);
|
||||||
int _ignore = TRY(Result<int>::from_syscall(rc));
|
|
||||||
|
|
||||||
ignore(_ignore);
|
return Result<void>::from_syscall(rc);
|
||||||
|
|
||||||
return {};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Result<void> remove(StringView path)
|
Result<void> remove(StringView path)
|
||||||
{
|
{
|
||||||
long rc = syscall(SYS_unlink, path.chars(), 0);
|
long rc = syscall(SYS_unlink, path.chars(), 0);
|
||||||
int _ignore = TRY(Result<int>::from_syscall(rc));
|
|
||||||
|
|
||||||
ignore(_ignore);
|
return Result<void>::from_syscall(rc);
|
||||||
|
|
||||||
return {};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Result<String> working_directory()
|
Result<String> working_directory()
|
||||||
@ -70,10 +64,7 @@ namespace os::FileSystem
|
|||||||
Result<void> change_directory(StringView path)
|
Result<void> change_directory(StringView path)
|
||||||
{
|
{
|
||||||
long rc = syscall(SYS_chdir, path.chars());
|
long rc = syscall(SYS_chdir, path.chars());
|
||||||
int _ignore = TRY(Result<int>::from_syscall(rc));
|
|
||||||
|
|
||||||
ignore(_ignore);
|
return Result<void>::from_syscall(rc);
|
||||||
|
|
||||||
return {};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user