13c3268a9STrond Norbye/* LibMemcached
23c3268a9STrond Norbye * Copyright (C) 2010 Brian Aker, Trond Norbye
33c3268a9STrond Norbye * All rights reserved.
43c3268a9STrond Norbye *
53c3268a9STrond Norbye * Use and distribution licensed under the BSD license.  See
63c3268a9STrond Norbye * the COPYING file in the parent directory for full text.
73c3268a9STrond Norbye *
83c3268a9STrond Norbye * Summary: "Implementation" of the function we don't have on windows
93c3268a9STrond Norbye *          to avoid a bunch of ifdefs in the rest of the code
103c3268a9STrond Norbye *
113c3268a9STrond Norbye */
123c3268a9STrond Norbye#ifndef WIN32_WRAPPERS_H
133c3268a9STrond Norbye#define WIN32_WRAPPERS_H 1
143c3268a9STrond Norbye
153c3268a9STrond Norbye#include <inttypes.h>
163c3268a9STrond Norbye
173c3268a9STrond Norbye/*
183c3268a9STrond Norbye * One of the Windows headers define interface as a macro, but that
193c3268a9STrond Norbye * is causing problems with the member named "interface" in some of the
203c3268a9STrond Norbye * structs.
213c3268a9STrond Norbye */
223c3268a9STrond Norbye#undef interface
233c3268a9STrond Norbye
243c3268a9STrond Norbye#undef malloc
253c3268a9STrond Norbye#undef realloc
263c3268a9STrond Norbye
27dae52370STrond Norbye#if _MSC_VER < 1900
283c3268a9STrond Norbye#define snprintf _snprintf
29dae52370STrond Norbye#endif
303c3268a9STrond Norbye#define PRIu64 "I64u"
313c3268a9STrond Norbye
323c3268a9STrond Norbye#define poll(a,b,c) WSAPoll(a,b,c)
333c3268a9STrond Norbye
343c3268a9STrond Norbye#define gettimeofday(a, b) win_gettimeofday(a)
353c3268a9STrond Norbyeextern int win_gettimeofday(struct timeval *t);
363c3268a9STrond Norbye#define strdup(a) _strdup(a)
373c3268a9STrond Norbye#define strtoull(a, b, c) _strtoui64(a, b, c)
383c3268a9STrond Norbye#define strtoll(a, b, c) _strtoi64(a, b, c)
393c3268a9STrond Norbye
403c3268a9STrond Norbye#define getsockopt(a, b, c, d, e) win_getsockopt(a, b, c, d, e)
413c3268a9STrond Norbyeextern int win_getsockopt(SOCKET s, int level, int optname, void *value, socklen_t *option_len);
423c3268a9STrond Norbye
433c3268a9STrond Norbye#define setsockopt(a, b, c, d, e) win_setsockopt(a, b, c, d, e)
443c3268a9STrond Norbyeextern int win_setsockopt(SOCKET s, int level, int optname, const void *value, socklen_t option_len);
453c3268a9STrond Norbye
463c3268a9STrond Norbye#if 0
473c3268a9STrond Norbye/*
483c3268a9STrond Norbye * WinSock use a separate range for error codes. Let's just map to the
493c3268a9STrond Norbye * WinSock ones.
503c3268a9STrond Norbye */
513c3268a9STrond Norbye#define EADDRINUSE WSAEADDRINUSE
523c3268a9STrond Norbye#define EWOULDBLOCK WSAEWOULDBLOCK
533c3268a9STrond Norbye#define EINPROGRESS WSAEINPROGRESS
543c3268a9STrond Norbye#define EALREADY WSAEALREADY
553c3268a9STrond Norbye#define EISCONN WSAEISCONN
563c3268a9STrond Norbye#define ENOTCONN WSAENOTCONN
573c3268a9STrond Norbye#define ENOBUFS WSAENOBUFS
583c3268a9STrond Norbye#define SHUT_RDWR SD_BOTH
593c3268a9STrond Norbye#endif
603c3268a9STrond Norbye
613c3268a9STrond Norbye/* EAI_SYSTEM isn't defined anywhere... just set it to... 11? */
623c3268a9STrond Norbye#define EAI_SYSTEM 11
633c3268a9STrond Norbye
643c3268a9STrond Norbye/* Best effort mapping of functions to alternative functions */
653c3268a9STrond Norbye#define index(a,b) strchr(a,b)
663c3268a9STrond Norbye#define rindex(a,b) strrchr(a,b)
673c3268a9STrond Norbye#define random() rand()
683c3268a9STrond Norbye#define kill(a, b) while (false) {}
693c3268a9STrond Norbye#define fork() (-1)
703c3268a9STrond Norbye#define waitpid(a,b,c) (-1)
713c3268a9STrond Norbye#define fnmatch(a,b,c) (-1)
723c3268a9STrond Norbye#define sleep(a) Sleep(a*1000)
733c3268a9STrond Norbye
743c3268a9STrond Norbye#endif /* WIN32_WRAPPERS_H */