732e6a06f04f15e79a88da3f7809f5e074d9b982
2 * Copyright (C) 2010 Brian Aker, Trond Norbye
5 * Use and distribution licensed under the BSD license. See
6 * the COPYING file in the parent directory for full text.
8 * Summary: "Implementation" of the function we don't have on windows
9 * to avoid a bunch of ifdefs in the rest of the code
17 * One of the Windows headers define interface as a macro, but that
18 * is causing problems with the member named "interface" in some of the
28 * WinSock use a separate range for error codes. Let's just map to the
32 # define EADDRINUSE WSAEADDRINUSE
36 # define EWOULDBLOCK WSAEWOULDBLOCK
40 # define EINPROGRESS WSAEINPROGRESS
44 # define EALREADY WSAEALREADY
48 # define EISCONN WSAEISCONN
52 # define ENOTCONN WSAENOTCONN
56 # define ENOBUFS WSAENOBUFS
60 # define SHUT_RDWR SD_BOTH
63 # define SHUT_WR SD_SEND
66 # define SHUT_RD SD_RECEIVE
69 /* EAI_SYSTEM isn't defined anywhere... just set it to... 11? */
71 # define EAI_SYSTEM 11
74 /* Best effort mapping of functions to alternative functions */
75 #define index(a,b) strchr(a,b)
76 #define rindex(a,b) strrchr(a,b)
77 #define random() rand()
78 #define srandom(a) while (false) {}
79 #define kill(a, b) while (false) {}
81 #define waitpid(a,b,c) (-1)
82 #define fnmatch(a,b,c) (-1)
83 #define sleep(a) Sleep(a*1000)
87 static inline int gettimeofday(struct timeval
* tp
, struct timezone
* tzp
) {
88 using clock
= std::chrono::system_clock
;
89 auto as_sec
= [] (auto d
) {
90 return std::chrono::duration_cast
<std::chrono::seconds
>(d
);
92 auto as_usec
= [] (auto d
) {
93 return std::chrono::duration_cast
<std::chrono::microseconds
>(d
);
96 auto now
= clock::now().time_since_epoch();
97 auto sec
= as_sec(now
);
98 auto usec
= as_usec(now
- sec
);
100 tp
->tv_sec
= sec
.count();
101 tp
->tv_usec
= usec
.count();