commit 1b4296831a60983adaaaab680ebacc03833f2ae5 (tree)
parent 4ec26be424506ed312639405b37bc68d00ccde4e
Author: xackus <14938807+xackus@users.noreply.github.com>
Date: Sun, 4 Oct 2020 23:55:33 +0200
simplify api and add smoke test
Diffstat:
2 files changed, 18 insertions(+), 5 deletions(-)
diff --git a/lib/std/os.zig b/lib/std/os.zig
@@ -5413,10 +5413,12 @@ pub fn prctl(option: i32, args: anytype) PrctlError!u31 {
pub const GetrlimitError = UnexpectedError;
-pub fn getrlimit(resource: rlimit_resource, limits: *rlimit) GetrlimitError!void {
- const rc = system.getrlimit(resource, limits);
+pub fn getrlimit(resource: rlimit_resource) GetrlimitError!rlimit {
+ // TODO implement for systems other than linux and enable test
+ var limits: rlimit = undefined;
+ const rc = system.getrlimit(resource, &limits);
switch (errno(rc)) {
- 0 => return,
+ 0 => return limits,
EFAULT => unreachable, // bogus pointer
EINVAL => unreachable,
else => |err| return std.os.unexpectedErrno(err),
@@ -5427,8 +5429,9 @@ pub const SetrlimitError = error{
PermissionDenied,
} || UnexpectedError;
-pub fn setrlimit(resource: rlimit_resource, limits: *const rlimit) SetrlimitError!void {
- const rc = system.setrlimit(resource, limits);
+pub fn setrlimit(resource: rlimit_resource, limits: rlimit) SetrlimitError!void {
+ // TODO implement for systems other than linux and enable test
+ const rc = system.setrlimit(resource, &limits);
switch (errno(rc)) {
0 => return,
EFAULT => unreachable, // bogus pointer
diff --git a/lib/std/os/test.zig b/lib/std/os/test.zig
@@ -591,3 +591,13 @@ test "fsync" {
try os.fsync(file.handle);
try os.fdatasync(file.handle);
}
+
+test "getrlimit and setrlimit" {
+ // TODO enable for other systems when implemented
+ if(builtin.os.tag != .linux){
+ return error.SkipZigTest;
+ }
+
+ const cpuLimit = try os.getrlimit(.CPU);
+ try os.setrlimit(.CPU, cpuLimit);
+}