xref: /6.0.3/moxi/libmemcached/win32/wrappers.h (revision dae52370)
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#if _MSC_VER < 1900
28#define snprintf _snprintf
29#endif
30#define PRIu64 "I64u"
31
32#define poll(a,b,c) WSAPoll(a,b,c)
33
34#define gettimeofday(a, b) win_gettimeofday(a)
35extern int win_gettimeofday(struct timeval *t);
36#define strdup(a) _strdup(a)
37#define strtoull(a, b, c) _strtoui64(a, b, c)
38#define strtoll(a, b, c) _strtoi64(a, b, c)
39
40#define getsockopt(a, b, c, d, e) win_getsockopt(a, b, c, d, e)
41extern int win_getsockopt(SOCKET s, int level, int optname, void *value, socklen_t *option_len);
42
43#define setsockopt(a, b, c, d, e) win_setsockopt(a, b, c, d, e)
44extern int win_setsockopt(SOCKET s, int level, int optname, const void *value, socklen_t option_len);
45
46#if 0
47/*
48 * WinSock use a separate range for error codes. Let's just map to the
49 * WinSock ones.
50 */
51#define EADDRINUSE WSAEADDRINUSE
52#define EWOULDBLOCK WSAEWOULDBLOCK
53#define EINPROGRESS WSAEINPROGRESS
54#define EALREADY WSAEALREADY
55#define EISCONN WSAEISCONN
56#define ENOTCONN WSAENOTCONN
57#define ENOBUFS WSAENOBUFS
58#define SHUT_RDWR SD_BOTH
59#endif
60
61/* EAI_SYSTEM isn't defined anywhere... just set it to... 11? */
62#define EAI_SYSTEM 11
63
64/* Best effort mapping of functions to alternative functions */
65#define index(a,b) strchr(a,b)
66#define rindex(a,b) strrchr(a,b)
67#define random() rand()
68#define kill(a, b) while (false) {}
69#define fork() (-1)
70#define waitpid(a,b,c) (-1)
71#define fnmatch(a,b,c) (-1)
72#define sleep(a) Sleep(a*1000)
73
74#endif /* WIN32_WRAPPERS_H */
75