mirror of
https://codeberg.org/ziglang/zig.git
synced 2026-05-08 02:38:00 +03:00
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:
committed by
Alex Rønne Petersen
parent
0ec456c785
commit
52c5223bca
+13
-11
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user