authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-05-26 18:01:54 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-05-26 18:01:54 -07:00
log9edefde5fcf96894b6aa4ab60241940bba65debf
treed94d6f3c3d2ed94412646d2e30b09f39adbe7eac
parent6c9cf95932c44fde8e4560cdd96f74a4cc1ebee2
signaturebadge-check Signed by SSH key SHA256:4hHJbtBRU58AYXwjL7fkz2fnQHdiye8x1QpTCQ0sHNw

add waitpid


2 files changed, 46 insertions(+), 0 deletions(-)

mod.zig+45
...@@ -2759,6 +2759,10 @@ pub const libc = struct {...@@ -2759,6 +2759,10 @@ pub const libc = struct {
2759 /// https://pubs.opengroup.org/onlinepubs/9699919799.orig/functions/uselocale.html2759 /// https://pubs.opengroup.org/onlinepubs/9699919799.orig/functions/uselocale.html
2760 pub extern fn uselocale(newloc: locale_t) locale_t;2760 pub extern fn uselocale(newloc: locale_t) locale_t;
27612761
2762 /// pid_t waitpid(pid_t pid, int *stat_loc, int options);
2763 /// https://pubs.opengroup.org/onlinepubs/9699919799.orig/functions/waitpid.html
2764 pub extern fn waitpid(pid: pid_t, stat_loc: ?*c_int, options: c_int) pid_t;
2765
2762 /// int wctob(wint_t c);2766 /// int wctob(wint_t c);
2763 /// https://pubs.opengroup.org/onlinepubs/9699919799.orig/functions/wctob.html2767 /// https://pubs.opengroup.org/onlinepubs/9699919799.orig/functions/wctob.html
2764 pub extern fn wctob(c: wint_t) c_int;2768 pub extern fn wctob(c: wint_t) c_int;
...@@ -3271,6 +3275,40 @@ pub const POLL = struct {...@@ -3271,6 +3275,40 @@ pub const POLL = struct {
3271 pub const RDHUP = 0x2000;3275 pub const RDHUP = 0x2000;
3272};3276};
32733277
3278pub const W = struct {
3279 pub const NOHANG = 1;
3280 pub const UNTRACED = 2;
3281 pub const STOPPED = 2;
3282 pub const EXITED = 4;
3283 pub const CONTINUED = 8;
3284 pub const NOWAIT = 0x1000000;
3285
3286 pub fn EXITSTATUS(s: c_int) u8 {
3287 return @intCast((s & 0xff00) >> 8);
3288 }
3289 pub fn TERMSIG(s: c_int) u8 {
3290 return @intCast(s & 0x7f);
3291 }
3292 pub fn STOPSIG(s: c_int) u8 {
3293 return EXITSTATUS(s);
3294 }
3295 pub fn COREDUMP(s: c_int) c_uint {
3296 return s & 0x80;
3297 }
3298 pub fn IFEXITED(s: c_int) bool {
3299 return TERMSIG(s) == 0;
3300 }
3301 pub fn IFSTOPPED(s: c_int) bool {
3302 return ((s & 0xffff) *% 0x10001) >> 8 > 0x7f00;
3303 }
3304 pub fn IFSIGNALED(s: c_int) bool {
3305 return s & 0xffff -% 1 < 0xff;
3306 }
3307 pub fn IFCONTINUED(s: c_int) bool {
3308 return s == 0xffff;
3309 }
3310};
3311
3274pub fn getpid() pid_t {3312pub fn getpid() pid_t {
3275 return libc.getpid();3313 return libc.getpid();
3276}3314}
...@@ -3646,3 +3684,10 @@ pub fn poll(fds: []struct_pollfd, timeout_ms: c_int) !c_int {...@@ -3646,3 +3684,10 @@ pub fn poll(fds: []struct_pollfd, timeout_ms: c_int) !c_int {
3646 std.debug.assert(rc >= 0);3684 std.debug.assert(rc >= 0);
3647 return rc;3685 return rc;
3648}3686}
3687pub fn waitpid(pid: pid_t, options: c_int) !struct { pid_t, c_int } {
3688 var status: c_int = 0;
3689 const rc = libc.waitpid(pid, &status, options);
3690 if (rc == -1) return errno.fromInt(errno.fromLibC());
3691 std.debug.assert(rc >= 0);
3692 return .{ rc, status };
3693}
test.zig+1
...@@ -77,4 +77,5 @@ test {...@@ -77,4 +77,5 @@ test {
77 _ = &linux.execvp;77 _ = &linux.execvp;
78 _ = &linux.dup2;78 _ = &linux.dup2;
79 _ = &linux.poll;79 _ = &linux.poll;
80 _ = &linux.waitpid;
80}81}