ish/kernel/poll.c
Theodore Dubois f1e63c43e0 Rename sys directory to kernel
A number of the headers in it were conflicting with macOS system
headers.
2017-10-13 16:54:11 -07:00

28 lines
719 B
C

#include "debug.h"
#include "kernel/fs.h"
#include "kernel/calls.h"
dword_t sys_poll(addr_t fds, dword_t nfds, dword_t timeout) {
if (nfds != 1)
TODO("actual working poll");
struct pollfd_ fake_poll;
if (user_get(fds, fake_poll))
return _EFAULT;
struct poll *poll = poll_create();
if (poll == NULL)
return _ENOMEM;
poll_add_fd(poll, current->files[fake_poll.fd], fake_poll.events);
struct poll_event event;
int err = poll_wait(poll, &event, timeout);
if (err < 0) {
poll_destroy(poll);
return err;
}
fake_poll.revents = event.types;
poll_destroy(poll);
if (user_put(fds, fake_poll))
return _EFAULT;
return err;
}