LibCore: Add system call wrappers around getrlimit and setrlimit

This commit is contained in:
Timothy Flynn 2024-07-22 10:11:18 -04:00 committed by Andreas Kling
commit 0d6115e8ae
Notes: github-actions[bot] 2024-07-23 07:40:42 +00:00
2 changed files with 25 additions and 0 deletions

View file

@ -1848,4 +1848,25 @@ ErrorOr<Bytes> allocate(size_t count, size_t size)
return Bytes { data, size * count };
}
ErrorOr<rlimit> get_resource_limits(int resource)
{
rlimit limits;
if (::getrlimit(resource, &limits) != 0)
return Error::from_errno(errno);
return limits;
}
ErrorOr<void> set_resource_limits(int resource, rlim_t limit)
{
auto limits = TRY(get_resource_limits(resource));
limits.rlim_cur = limit;
if (::setrlimit(resource, &limits) != 0)
return Error::from_errno(errno);
return {};
}
}