Import Upstream version 20180207
[hcoop/debian/mlton.git] / runtime / basis / System / OS / IO / poll.c
1 #include "platform.h"
2
3 C_Errno_t(C_Int_t)
4 OS_IO_poll (Vector(C_Fd_t) fds,
5 Vector(C_Short_t) eventss,
6 C_NFds_t n,
7 C_Int_t timeout,
8 Array(C_Short_t) reventss) {
9 unsigned int i;
10 int res;
11 struct pollfd ufds[n];
12
13 for (i = 0; i < n; i++) {
14 ufds[i].fd = ((const int*)fds)[i];
15 ufds[i].events = ((const short*)eventss)[i];
16 }
17 res = poll (ufds, n, timeout);
18 for (i = 0; i < n; i++) {
19 ((short*)reventss)[i] = ufds[i].revents;
20 }
21 return res;
22 }