diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2020-10-16 18:15:31 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2020-10-16 18:15:31 -0700 |
| commit | 2aff27d92247eed3b64ffc68da8fae9e5994ea0b (patch) | |
| tree | f8287a9f1e07269c5ebd2d3e0a86483c23270e25 /lib/std/os.zig | |
| parent | 0e4c3934a02cda80a72a730593ece41c7fa8026a (diff) | |
| parent | 5c16022c81effc2d684aaf21217dce0f7708946a (diff) | |
| download | zig-2aff27d92247eed3b64ffc68da8fae9e5994ea0b.tar.gz zig-2aff27d92247eed3b64ffc68da8fae9e5994ea0b.zip | |
Merge branch '6604'
closes #6604
Diffstat (limited to 'lib/std/os.zig')
| -rw-r--r-- | lib/std/os.zig | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/lib/std/os.zig b/lib/std/os.zig index bc7dae031c..4a06d3c0bb 100644 --- a/lib/std/os.zig +++ b/lib/std/os.zig @@ -3121,16 +3121,24 @@ pub fn getsockoptError(sockfd: fd_t) ConnectError!void { } } -pub fn waitpid(pid: i32, flags: u32) u32 { - // TODO allow implicit pointer cast from *u32 to *c_uint ? +pub const WaitPidResult = struct { + pid: pid_t, + status: u32, +}; + +pub fn waitpid(pid: pid_t, flags: u32) WaitPidResult { const Status = if (builtin.link_libc) c_uint else u32; var status: Status = undefined; while (true) { - switch (errno(system.waitpid(pid, &status, flags))) { - 0 => return @bitCast(u32, status), + const rc = system.waitpid(pid, &status, flags); + switch (errno(rc)) { + 0 => return .{ + .pid = @intCast(pid_t, rc), + .status = @bitCast(u32, status), + }, EINTR => continue, ECHILD => unreachable, // The process specified does not exist. It would be a race condition to handle this error. - EINVAL => unreachable, // The options argument was invalid + EINVAL => unreachable, // Invalid flags. else => unreachable, } } @@ -5434,9 +5442,7 @@ pub fn getrlimit(resource: rlimit_resource) GetrlimitError!rlimit { } } -pub const SetrlimitError = error{ - PermissionDenied, -} || UnexpectedError; +pub const SetrlimitError = error{PermissionDenied} || UnexpectedError; pub fn setrlimit(resource: rlimit_resource, limits: rlimit) SetrlimitError!void { // TODO implement for systems other than linux and enable test |
