ci: bsds: rebuild packages after reconfiguration
[m6w6/libmemcached] / src / win32 / wrappers.h
1 /* LibMemcached
2 * Copyright (C) 2010 Brian Aker, Trond Norbye
3 * All rights reserved.
4 *
5 * Use and distribution licensed under the BSD license. See
6 * the COPYING file in the parent directory for full text.
7 *
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
10 *
11 */
12 #pragma once
13
14 #include <inttypes.h>
15
16 /*
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
19 * structs.
20 */
21 #undef interface
22
23 #undef malloc
24 #undef realloc
25
26
27 /*
28 * WinSock use a separate range for error codes. Let's just map to the
29 * WinSock ones.
30 */
31 #ifndef EADDRINUSE
32 # define EADDRINUSE WSAEADDRINUSE
33 #endif
34
35 #ifndef EWOULDBLOCK
36 # define EWOULDBLOCK WSAEWOULDBLOCK
37 #endif
38
39 #ifndef EINPROGRESS
40 # define EINPROGRESS WSAEINPROGRESS
41 #endif
42
43 #ifndef EALREADY
44 # define EALREADY WSAEALREADY
45 #endif
46
47 #ifndef EISCONN
48 # define EISCONN WSAEISCONN
49 #endif
50
51 #ifndef ENOTCONN
52 # define ENOTCONN WSAENOTCONN
53 #endif
54
55 #ifndef ENOBUFS
56 # define ENOBUFS WSAENOBUFS
57 #endif
58
59 #ifndef SHUT_RDWR
60 # define SHUT_RDWR SD_BOTH
61 #endif
62 #ifndef SHUT_WR
63 # define SHUT_WR SD_SEND
64 #endif
65 #ifndef SHUT_RD
66 # define SHUT_RD SD_RECEIVE
67 #endif
68
69 /* EAI_SYSTEM isn't defined anywhere... just set it to... 11? */
70 #ifndef EAI_SYSTEM
71 # define EAI_SYSTEM 11
72 #endif
73
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) {}
80 #define fork() (-1)
81 #define waitpid(a,b,c) (-1)
82 #define fnmatch(a,b,c) (-1)
83 #define sleep(a) Sleep(a*1000)
84
85 #ifdef __cplusplus
86 # include <chrono>
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);
91 };
92 auto as_usec = [] (auto d) {
93 return std::chrono::duration_cast<std::chrono::microseconds>(d);
94 };
95
96 auto now = clock::now().time_since_epoch();
97 auto sec = as_sec(now);
98 auto usec = as_usec(now - sec);
99
100 tp->tv_sec = sec.count();
101 tp->tv_usec = usec.count();
102 return 0;
103 }
104 #endif