Initial AROS support.
[deb_libnfs.git] / aros / aros_compat.c
1 /*
2 Copyright (C) 2013 by Ronnie Sahlberg <ronniesahlberg@gmail.com>
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU Lesser General Public License as published by
6 the Free Software Foundation; either version 2.1 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public License
15 along with this program; if not, see <http://www.gnu.org/licenses/>.
16 */
17
18 #ifdef AROS
19
20 #include <sys/types.h>
21 #include <sys/time.h>
22 #include "aros_compat.h"
23
24 #undef poll
25
26
27 int aros_poll(struct pollfd *fds, unsigned int nfds, int timo)
28 {
29 struct timeval timeout, *toptr;
30 fd_set ifds, ofds, efds, *ip, *op;
31 unsigned int i;
32 int rc;
33
34 // Set up the file-descriptor sets in ifds, ofds and efds.
35 FD_ZERO(&ifds);
36 FD_ZERO(&ofds);
37 FD_ZERO(&efds);
38 for (i = 0, op = ip = 0; i < nfds; ++i)
39 {
40 fds[i].revents = 0;
41 if(fds[i].events & (POLLIN|POLLPRI))
42 {
43 ip = &ifds;
44 FD_SET(fds[i].fd, ip);
45 }
46 if(fds[i].events & POLLOUT)
47 {
48 op = &ofds;
49 FD_SET(fds[i].fd, op);
50 }
51 FD_SET(fds[i].fd, &efds);
52 }
53
54 // Set up the timeval structure for the timeout parameter
55 if(timo < 0)
56 {
57 toptr = 0;
58 }
59 else
60 {
61 toptr = &timeout;
62 timeout.tv_sec = timo / 1000;
63 timeout.tv_usec = (timo - timeout.tv_sec * 1000) * 1000;
64 }
65
66 rc = select(0, ip, op, &efds, toptr);
67
68 if(rc <= 0)
69 return rc;
70
71 if(rc > 0)
72 {
73 for (i = 0; i < nfds; ++i)
74 {
75 int fd = fds[i].fd;
76 if(fds[i].events & (POLLIN|POLLPRI) && FD_ISSET(fd, &ifds))
77 fds[i].revents |= POLLIN;
78 if(fds[i].events & POLLOUT && FD_ISSET(fd, &ofds))
79 fds[i].revents |= POLLOUT;
80 if(FD_ISSET(fd, &efds)) // Some error was detected ... should be some way to know.
81 fds[i].revents |= POLLHUP;
82 }
83 }
84 return rc;
85 }
86
87 #endif