std.os.linux: local variable for timeout in poll

The linux syscall ppoll modifies its second argument, thus using
`@constCast` here is not correct.
This commit is contained in:
Jari Vetoniemi
2026-03-20 04:53:35 +09:00
committed by Alex Rønne Petersen
parent 0ec456c785
commit 52c5223bca
+13 -11
View File
@@ -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(&timespec{
.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 {