summaryrefslogtreecommitdiffstats
path: root/usr/klibc/select.c
blob: 11e7154307fab60927e4e35d0121edca8c6faf8e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <sys/time.h>
#include <sys/types.h>
#include <sys/select.h>
#include <errno.h>
#include <sys/syscall.h>

struct __pselect6;
__extern int __pselect6(int, fd_set *, fd_set *, fd_set *,
			const struct timespec *, const struct __pselect6 *);

int select(int nfds, fd_set *readfds, fd_set *writefds,
	   fd_set *exceptfds, struct timeval *timeout)
{
	int result;
	struct timespec ts;

	if (timeout) {
		ts.tv_sec = timeout->tv_sec;
		ts.tv_nsec = timeout->tv_usec * 1000;
	}

	result = __pselect6(nfds, readfds, writefds, exceptfds,
			    timeout ? &ts : NULL, NULL);

	if (timeout) {
		timeout->tv_sec = ts.tv_sec;
		timeout->tv_usec = ts.tv_nsec / 1000;
	}

	return result;
}