authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-05-26 18:01:46 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-05-26 18:01:46 -07:00
log6c9cf95932c44fde8e4560cdd96f74a4cc1ebee2
tree6bad1d3d09640b7eb48140e2b9bf297ed3a84fa9
parent79207de4d29b7da5552bc52acd7443f8868404c4
signaturebadge-check Signed by SSH key SHA256:4hHJbtBRU58AYXwjL7fkz2fnQHdiye8x1QpTCQ0sHNw

add poll


2 files changed, 28 insertions(+), 0 deletions(-)

mod.zig+27
...@@ -2167,6 +2167,10 @@ pub const libc = struct {...@@ -2167,6 +2167,10 @@ pub const libc = struct {
2167 /// https://pubs.opengroup.org/onlinepubs/9799919799/functions/pipe.html2167 /// https://pubs.opengroup.org/onlinepubs/9799919799/functions/pipe.html
2168 pub extern fn pipe2(pipefd: *[2]c_int, flag: c_int) c_int;2168 pub extern fn pipe2(pipefd: *[2]c_int, flag: c_int) c_int;
21692169
2170 /// int poll(struct pollfd fds[], nfds_t nfds, int timeout);
2171 /// https://pubs.opengroup.org/onlinepubs/9699919799.orig/functions/poll.html
2172 pub extern fn poll(fds: [*]struct_pollfd, nfds: nfds_t, timeout: c_int) c_int;
2173
2170 /// double pow(double x, double y);2174 /// double pow(double x, double y);
2171 /// https://pubs.opengroup.org/onlinepubs/9699919799.orig/functions/pow.html2175 /// https://pubs.opengroup.org/onlinepubs/9699919799.orig/functions/pow.html
2172 pub extern fn pow(x: f64, y: f64) f64;2176 pub extern fn pow(x: f64, y: f64) f64;
...@@ -2856,6 +2860,8 @@ pub const struct_sockaddr_un = extern struct { family: AF = .UNIX, path: [108]u8...@@ -2856,6 +2860,8 @@ pub const struct_sockaddr_un = extern struct { family: AF = .UNIX, path: [108]u8
2856pub const struct_addrinfo = extern struct { flags: c_int, family: c_int, socktype: c_int, protocol: c_int, addrlen: socklen_t, addr: ?*struct_sockaddr, canonname: ?[*:0]u8, next: ?*struct_addrinfo };2860pub const struct_addrinfo = extern struct { flags: c_int, family: c_int, socktype: c_int, protocol: c_int, addrlen: socklen_t, addr: ?*struct_sockaddr, canonname: ?[*:0]u8, next: ?*struct_addrinfo };
2857pub const struct_dirent = extern struct { ino: ino_t, off: off_t, reclen: c_ushort, type: DT, name: [NAME_MAX + 1]u8 };2861pub const struct_dirent = extern struct { ino: ino_t, off: off_t, reclen: c_ushort, type: DT, name: [NAME_MAX + 1]u8 };
2858pub const cpu_set_t = [1024 / 8 / @sizeOf(c_ulong)]c_ulong;2862pub const cpu_set_t = [1024 / 8 / @sizeOf(c_ulong)]c_ulong;
2863pub const nfds_t = c_ulong;
2864pub const struct_pollfd = extern struct { fd: c_int, events: c_short, revents: c_short };
28592865
2860const impdef = @cImport({2866const impdef = @cImport({
2861 @cInclude("pthread.h");2867 @cInclude("pthread.h");
...@@ -3250,6 +3256,21 @@ pub const SIG = struct {...@@ -3250,6 +3256,21 @@ pub const SIG = struct {
3250 pub const UNUSED = SYS;3256 pub const UNUSED = SYS;
3251};3257};
32523258
3259pub const POLL = struct {
3260 pub const IN = 0x001;
3261 pub const PRI = 0x002;
3262 pub const OUT = 0x004;
3263 pub const ERR = 0x008;
3264 pub const HUP = 0x010;
3265 pub const NVAL = 0x020;
3266 pub const RDNORM = 0x040;
3267 pub const RDBAND = 0x080;
3268 pub const WRNORM = if (arch.isMIPS()) OUT else 0x100;
3269 pub const WRBAND = if (arch.isMIPS()) 0x100 else 0x200;
3270 pub const MSG = 0x400;
3271 pub const RDHUP = 0x2000;
3272};
3273
3253pub fn getpid() pid_t {3274pub fn getpid() pid_t {
3254 return libc.getpid();3275 return libc.getpid();
3255}3276}
...@@ -3619,3 +3640,9 @@ pub fn dup2(fildes: c_int, fildes2: c_int) !void {...@@ -3619,3 +3640,9 @@ pub fn dup2(fildes: c_int, fildes2: c_int) !void {
3619 if (rc == -1) return errno.fromInt(errno.fromLibC());3640 if (rc == -1) return errno.fromInt(errno.fromLibC());
3620 std.debug.assert(rc >= 0);3641 std.debug.assert(rc >= 0);
3621}3642}
3643pub fn poll(fds: []struct_pollfd, timeout_ms: c_int) !c_int {
3644 const rc = libc.poll(fds.ptr, fds.len, timeout_ms);
3645 if (rc == -1) return errno.fromInt(errno.fromLibC());
3646 std.debug.assert(rc >= 0);
3647 return rc;
3648}
test.zig+1
...@@ -76,4 +76,5 @@ test {...@@ -76,4 +76,5 @@ test {
76 _ = &linux.fchdir;76 _ = &linux.fchdir;
77 _ = &linux.execvp;77 _ = &linux.execvp;
78 _ = &linux.dup2;78 _ = &linux.dup2;
79 _ = &linux.poll;
79}80}