commit 52c5223bca7c4e6269488288bc087a4cf94dd283 (tree)
parent 0ec456c785aa2fe8fa686fd19282a887f3cbe8eb
Author: Jari Vetoniemi <jari.vetoniemi@cloudef.pw>
Date: Fri, 20 Mar 2026 04:53:35 +0900
std.os.linux: local variable for timeout in poll
The linux syscall ppoll modifies its second argument, thus using
`@constCast` here is not correct.
Diffstat:
1 file changed, 13 insertions(+), 11 deletions(-)
diff --git 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 {