diff options
| author | stf <7o5rfu92t@ctrlc.hu> | 2020-10-07 18:51:04 +0000 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2020-10-16 17:26:50 -0700 |
| commit | 3921cb0d8d46c59411b6c8f35f5d271c26fba14f (patch) | |
| tree | dec306becc1dfcc32e7276c635eb09dbcd0e5773 /lib/std/os.zig | |
| parent | 0e4c3934a02cda80a72a730593ece41c7fa8026a (diff) | |
| download | zig-3921cb0d8d46c59411b6c8f35f5d271c26fba14f.tar.gz zig-3921cb0d8d46c59411b6c8f35f5d271c26fba14f.zip | |
std.os.waitpid: also return pid of child
closes #6581
Diffstat (limited to 'lib/std/os.zig')
| -rw-r--r-- | lib/std/os.zig | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/lib/std/os.zig b/lib/std/os.zig index bc7dae031c..48c1cee6fd 100644 --- a/lib/std/os.zig +++ b/lib/std/os.zig @@ -3121,13 +3121,18 @@ pub fn getsockoptError(sockfd: fd_t) ConnectError!void { } } -pub fn waitpid(pid: i32, flags: u32) u32 { +pub const WaitpidRet = struct { + pid: pid_t, status: u32 +}; + +pub fn waitpid(pid: pid_t, flags: u32) WaitpidRet { // TODO allow implicit pointer cast from *u32 to *c_uint ? 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 WaitpidRet{ .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 |
