From 52c5223bca7c4e6269488288bc087a4cf94dd283 Mon Sep 17 00:00:00 2001 From: Jari Vetoniemi Date: Fri, 20 Mar 2026 04:53:35 +0900 Subject: [PATCH] std.os.linux: local variable for timeout in poll The linux syscall ppoll modifies its second argument, thus using `@constCast` here is not correct. --- lib/std/os/linux.zig | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/lib/std/os/linux.zig b/lib/std/os/linux.zig index 98c3f6131e..8e6ec0dec4 100644 --- a/lib/std/os/linux.zig +++ b/lib/std/os/linux.zig @@ -1256,21 +1256,23 @@ pub fn munlockall() usize { } pub fn poll(fds: [*]pollfd, n: nfds_t, timeout: i32) usize { - return if (@hasField(SYS, "poll")) - return syscall3(.poll, @intFromPtr(fds), n, @as(u32, @bitCast(timeout))) - else - ppoll( + if (@hasField(SYS, "poll")) { + return syscall3(.poll, @intFromPtr(fds), n, @as(u32, @bitCast(timeout))); + } else { + var ts: timespec = if (timeout >= 0) + .{ + .sec = @divTrunc(timeout, 1000), + .nsec = @rem(timeout, 1000) * 1000000, + } + else + undefined; + return ppoll( fds, n, - if (timeout >= 0) - @constCast(×pec{ - .sec = @divTrunc(timeout, 1000), - .nsec = @rem(timeout, 1000) * 1000000, - }) - else - null, + if (timeout >= 0) &ts else null, null, ); + } } pub fn ppoll(fds: [*]pollfd, n: nfds_t, timeout: ?*timespec, sigmask: ?*const sigset_t) usize {