Commit 1b4296831a
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);
+}
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