Make the zlib compile against the tinycrt library.
[git-build-vc9.git] / tcrt / src / select.cpp
blobdfaac75f664573546e70b7c0b11db61b66729604
1 /*=============================================================================
2 select.cpp :
4 Copyright © 2008 Bruno Santos <nayart3@gmail.com>
5 =============================================================================*/
7 #include <sys/select.h>
8 #include <string.h>
9 #include <errno.h>
10 #include "Ws2_32.h"
12 ///////////////////////////////////////////////////////////////////////////////
13 void FD_ZERO(fd_set* fs)
15 memset(fs, 0, sizeof(fd_set));
18 void FD_SET(int fildes, fd_set* fs)
20 HANDLE hd = tcrt::fildes_to_handle(fildes);
22 if (fs->count >= FD_SETSIZE)
23 return;
24 for (uint i = 0; i < fs->count; ++i) {
25 if (fs->fildes[i] == hd)
26 return;
28 fs->fildes[fs->count++] = hd;
31 int FD_ISSET(int fildes, fd_set* fs)
33 return Ws2_FDIsSet(tcrt::fildes_to_handle(fildes), fs);
36 int select(int nfds, fd_set* readfds, fd_set* writefds, fd_set* errorfds, struct timeval* timeout)
38 int ret;
40 if (!nfds) {
41 DWORD msec = timeout->tv_sec * 1000 + timeout->tv_usec / 1000;
42 Sleep(msec);
44 ret = Ws2_Select(nfds, readfds, writefds, errorfds, timeout);
45 if (ret < 0) {
46 errno = Ws2_GetLastError();
47 return -1;
49 return ret;
52 // EOF ////////////////////////////////////////////////////////////////////////