From f340bdfff52c148a94fcb844b80d9048bd419e79 Mon Sep 17 00:00:00 2001 From: Meghan Denny Date: Tue, 26 May 2026 17:59:07 -0700 Subject: [PATCH] add pipe2 --- mod.zig | 11 +++++++++++ test.zig | 1 + 2 files changed, 12 insertions(+) diff --git a/mod.zig b/mod.zig index e261224f3e9602760172158cc644bbeb9add708e..56ffbc61ba4ac1ffe09e79fb51e947acd5c78751 100644 --- a/mod.zig +++ b/mod.zig @@ -2155,6 +2155,10 @@ pub const libc = struct { /// https://pubs.opengroup.org/onlinepubs/9699919799.orig/functions/pause.html pub extern fn pause() c_int; + /// int pipe2(int fildes[2], int flag); + /// https://pubs.opengroup.org/onlinepubs/9799919799/functions/pipe.html + pub extern fn pipe2(pipefd: *[2]c_int, flag: c_int) c_int; + /// double pow(double x, double y); /// https://pubs.opengroup.org/onlinepubs/9699919799.orig/functions/pow.html pub extern fn pow(x: f64, y: f64) f64; @@ -3537,3 +3541,10 @@ pub fn pthread_rwlock_unlock(rwlock: *pthread_rwlock_t) !void { const rc = libc.pthread_rwlock_unlock(rwlock); if (rc != 0) return errno.fromInt(rc); } +pub fn pipe2(flag: c_int) ![2]c_int { + var fildes: [2]c_int = @splat(-1); + const rc = libc.pipe2(&fildes, flag); + if (rc == -1) return errno.fromInt(errno.fromLibC()); + std.debug.assert(rc == 0); + return fildes; +} diff --git a/test.zig b/test.zig index f3cff19aa43e1a24a4afeeedf9c70fd352b40a27..8815a275c44a0e809b0b6942c32d97318086e812 100644 --- a/test.zig +++ b/test.zig @@ -70,4 +70,5 @@ test { _ = &linux.pthread_rwlock_wrlock; _ = &linux.pthread_rwlock_trywrlock; _ = &linux.pthread_rwlock_unlock; + _ = &linux.pipe2; } -- 2.54.0