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 #ifndef WIN32_WRAPPERS_H
13 #define WIN32_WRAPPERS_H 1
14 
15 #include <inttypes.h>
16 
17 /*
18  * One of the Windows headers define interface as a macro, but that
19  * is causing problems with the member named "interface" in some of the
20  * structs.
21  */
22 #undef interface
23 
24 #undef malloc
25 #undef realloc
26 
27 #define snprintf _snprintf
28 #define PRIu64 "I64u"
29 
30 #define poll(a,b,c) WSAPoll(a,b,c)
31 
32 #define gettimeofday(a, b) win_gettimeofday(a)
33 extern int win_gettimeofday(struct timeval *t);
34 #define strdup(a) _strdup(a)
35 #define strtoull(a, b, c) _strtoui64(a, b, c)
36 #define strtoll(a, b, c) _strtoi64(a, b, c)
37 
38 #define getsockopt(a, b, c, d, e) win_getsockopt(a, b, c, d, e)
39 extern int win_getsockopt(SOCKET s, int level, int optname, void *value, socklen_t *option_len);
40 
41 #define setsockopt(a, b, c, d, e) win_setsockopt(a, b, c, d, e)
42 extern int win_setsockopt(SOCKET s, int level, int optname, const void *value, socklen_t option_len);
43 
44 #if 0
45 /*
46  * WinSock use a separate range for error codes. Let's just map to the
47  * WinSock ones.
48  */
49 #define EADDRINUSE WSAEADDRINUSE
50 #define EWOULDBLOCK WSAEWOULDBLOCK
51 #define EINPROGRESS WSAEINPROGRESS
52 #define EALREADY WSAEALREADY
53 #define EISCONN WSAEISCONN
54 #define ENOTCONN WSAENOTCONN
55 #define ENOBUFS WSAENOBUFS
56 #define SHUT_RDWR SD_BOTH
57 #endif
58 
59 /* EAI_SYSTEM isn't defined anywhere... just set it to... 11? */
60 #define EAI_SYSTEM 11
61 
62 /* Best effort mapping of functions to alternative functions */
63 #define index(a,b) strchr(a,b)
64 #define rindex(a,b) strrchr(a,b)
65 #define random() rand()
66 #define kill(a, b) while (false) {}
67 #define fork() (-1)
68 #define waitpid(a,b,c) (-1)
69 #define fnmatch(a,b,c) (-1)
70 #define sleep(a) Sleep(a*1000)
71 
72 #endif /* WIN32_WRAPPERS_H */
73