| ... | ... | @@ -3121,13 +3121,18 @@ pub fn getsockoptError(sockfd: fd_t) ConnectError!void { |
| 3121 | 3121 | } |
| 3122 | 3122 | } |
| 3123 | 3123 | |
| 3124 | | pub fn waitpid(pid: i32, flags: u32) u32 { |
| 3124 | pub const WaitpidRet = struct { |
| 3125 | pid: pid_t, status: u32 |
| 3126 | }; |
| 3127 | |
| 3128 | pub fn waitpid(pid: pid_t, flags: u32) WaitpidRet { |
| 3125 | 3129 | // TODO allow implicit pointer cast from *u32 to *c_uint ? |
| 3126 | 3130 | const Status = if (builtin.link_libc) c_uint else u32; |
| 3127 | 3131 | var status: Status = undefined; |
| 3128 | 3132 | while (true) { |
| 3129 | | switch (errno(system.waitpid(pid, &status, flags))) { |
| 3130 | | 0 => return @bitCast(u32, status), |
| 3133 | const rc = system.waitpid(pid, &status, flags); |
| 3134 | switch (errno(rc)) { |
| 3135 | 0 => return WaitpidRet{ .pid = @intCast(pid_t, rc), .status = @bitCast(u32, status) }, |
| 3131 | 3136 | EINTR => continue, |
| 3132 | 3137 | ECHILD => unreachable, // The process specified does not exist. It would be a race condition to handle this error. |
| 3133 | 3138 | EINVAL => unreachable, // The options argument was invalid |