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 {
21672167 /// https://pubs.opengroup.org/onlinepubs/9799919799/functions/pipe.html
21682168 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
21702174 /// double pow(double x, double y);
21712175 /// https://pubs.opengroup.org/onlinepubs/9699919799.orig/functions/pow.html
21722176 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
28562860pub 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 };
28572861pub const struct_dirent = extern struct { ino: ino_t, off: off_t, reclen: c_ushort, type: DT, name: [NAME_MAX + 1]u8 };
28582862pub 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
28602866const impdef = @cImport({
28612867 @cInclude("pthread.h");
......@@ -3250,6 +3256,21 @@ pub const SIG = struct {
32503256 pub const UNUSED = SYS;
32513257};
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
32533274pub fn getpid() pid_t {
32543275 return libc.getpid();
32553276}
......@@ -3619,3 +3640,9 @@ pub fn dup2(fildes: c_int, fildes2: c_int) !void {
36193640 if (rc == -1) return errno.fromInt(errno.fromLibC());
36203641 std.debug.assert(rc >= 0);
36213642}
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 {
7676 _ = &linux.fchdir;
7777 _ = &linux.execvp;
7878 _ = &linux.dup2;
79 _ = &linux.poll;
7980}