authorgravatar for jari.vetoniemi@cloudef.pwJari Vetoniemi <jari.vetoniemi@cloudef.pw> 2026-03-20 04:53:35+09:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2026-05-07 05:45:20+02:00
log52c5223bca7c4e6269488288bc087a4cf94dd283
treea7d515bff67adad86880b26918e5b7f989b8af6a
parent0ec456c785aa2fe8fa686fd19282a887f3cbe8eb

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

The linux syscall ppoll modifies its second argument, thus using `@constCast` here is not correct.

1 files changed, 13 insertions(+), 11 deletions(-)

lib/std/os/linux.zig+13-11
...@@ -1256,21 +1256,23 @@ pub fn munlockall() usize {...@@ -1256,21 +1256,23 @@ pub fn munlockall() usize {
1256}1256}
12571257
1258pub fn poll(fds: [*]pollfd, n: nfds_t, timeout: i32) usize {1258pub fn poll(fds: [*]pollfd, n: nfds_t, timeout: i32) usize {
1259 return if (@hasField(SYS, "poll"))1259 if (@hasField(SYS, "poll")) {
1260 return syscall3(.poll, @intFromPtr(fds), n, @as(u32, @bitCast(timeout)))1260 return syscall3(.poll, @intFromPtr(fds), n, @as(u32, @bitCast(timeout)));
1261 else1261 } else {
1262 ppoll(1262 var ts: timespec = if (timeout >= 0)
1263 .{
1264 .sec = @divTrunc(timeout, 1000),
1265 .nsec = @rem(timeout, 1000) * 1000000,
1266 }
1267 else
1268 undefined;
1269 return ppoll(
1263 fds,1270 fds,
1264 n,1271 n,
1265 if (timeout >= 0)1272 if (timeout >= 0) &ts else null,
1266 @constCast(&timespec{
1267 .sec = @divTrunc(timeout, 1000),
1268 .nsec = @rem(timeout, 1000) * 1000000,
1269 })
1270 else
1271 null,
1272 null,1273 null,
1273 );1274 );
1275 }
1274}1276}
12751277
1276pub fn ppoll(fds: [*]pollfd, n: nfds_t, timeout: ?*timespec, sigmask: ?*const sigset_t) usize {1278pub fn ppoll(fds: [*]pollfd, n: nfds_t, timeout: ?*timespec, sigmask: ?*const sigset_t) usize {