authorgravatar for 14938807+xackus@users.noreply.github.comxackus <14938807+xackus@users.noreply.github.com> 2020-10-04 23:55:33+02:00
committergravatar for 14938807+xackus@users.noreply.github.comxackus <14938807+xackus@users.noreply.github.com> 2020-10-04 23:57:49+02:00
log1b4296831a60983adaaaab680ebacc03833f2ae5
treedd7766fa76a59fbf48dd3eb1297129ad9c3e7c1d
parent4ec26be424506ed312639405b37bc68d00ccde4e

simplify api and add smoke test


2 files changed, 18 insertions(+), 5 deletions(-)

lib/std/os.zig+8-5
......@@ -5413,10 +5413,12 @@ pub fn prctl(option: i32, args: anytype) PrctlError!u31 {
54135413
54145414pub const GetrlimitError = UnexpectedError;
54155415
5416pub fn getrlimit(resource: rlimit_resource, limits: *rlimit) GetrlimitError!void {
5417 const rc = system.getrlimit(resource, limits);
5416pub fn getrlimit(resource: rlimit_resource) GetrlimitError!rlimit {
5417 // TODO implement for systems other than linux and enable test
5418 var limits: rlimit = undefined;
5419 const rc = system.getrlimit(resource, &limits);
54185420 switch (errno(rc)) {
5419 0 => return,
5421 0 => return limits,
54205422 EFAULT => unreachable, // bogus pointer
54215423 EINVAL => unreachable,
54225424 else => |err| return std.os.unexpectedErrno(err),
......@@ -5427,8 +5429,9 @@ pub const SetrlimitError = error{
54275429 PermissionDenied,
54285430} || UnexpectedError;
54295431
5430pub fn setrlimit(resource: rlimit_resource, limits: *const rlimit) SetrlimitError!void {
5431 const rc = system.setrlimit(resource, limits);
5432pub fn setrlimit(resource: rlimit_resource, limits: rlimit) SetrlimitError!void {
5433 // TODO implement for systems other than linux and enable test
5434 const rc = system.setrlimit(resource, &limits);
54325435 switch (errno(rc)) {
54335436 0 => return,
54345437 EFAULT => unreachable, // bogus pointer
lib/std/os/test.zig+10
......@@ -591,3 +591,13 @@ test "fsync" {
591591 try os.fsync(file.handle);
592592 try os.fdatasync(file.handle);
593593}
594
595test "getrlimit and setrlimit" {
596 // TODO enable for other systems when implemented
597 if(builtin.os.tag != .linux){
598 return error.SkipZigTest;
599 }
600
601 const cpuLimit = try os.getrlimit(.CPU);
602 try os.setrlimit(.CPU, cpuLimit);
603}