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
273c3268a9STrond Norbye#define snprintf _snprintf
283c3268a9STrond Norbye#define PRIu64 "I64u"
293c3268a9STrond Norbye
303c3268a9STrond Norbye#define poll(a,b,c) WSAPoll(a,b,c)
313c3268a9STrond Norbye
323c3268a9STrond Norbye#define gettimeofday(a, b) win_gettimeofday(a)
333c3268a9STrond Norbyeextern int win_gettimeofday(struct timeval *t);
343c3268a9STrond Norbye#define strdup(a) _strdup(a)
353c3268a9STrond Norbye#define strtoull(a, b, c) _strtoui64(a, b, c)
363c3268a9STrond Norbye#define strtoll(a, b, c) _strtoi64(a, b, c)
373c3268a9STrond Norbye
383c3268a9STrond Norbye#define getsockopt(a, b, c, d, e) win_getsockopt(a, b, c, d, e)
393c3268a9STrond Norbyeextern int win_getsockopt(SOCKET s, int level, int optname, void *value, socklen_t *option_len);
403c3268a9STrond Norbye
413c3268a9STrond Norbye#define setsockopt(a, b, c, d, e) win_setsockopt(a, b, c, d, e)
423c3268a9STrond Norbyeextern int win_setsockopt(SOCKET s, int level, int optname, const void *value, socklen_t option_len);
433c3268a9STrond Norbye
443c3268a9STrond Norbye#if 0
453c3268a9STrond Norbye/*
463c3268a9STrond Norbye * WinSock use a separate range for error codes. Let's just map to the
473c3268a9STrond Norbye * WinSock ones.
483c3268a9STrond Norbye */
493c3268a9STrond Norbye#define EADDRINUSE WSAEADDRINUSE
503c3268a9STrond Norbye#define EWOULDBLOCK WSAEWOULDBLOCK
513c3268a9STrond Norbye#define EINPROGRESS WSAEINPROGRESS
523c3268a9STrond Norbye#define EALREADY WSAEALREADY
533c3268a9STrond Norbye#define EISCONN WSAEISCONN
543c3268a9STrond Norbye#define ENOTCONN WSAENOTCONN
553c3268a9STrond Norbye#define ENOBUFS WSAENOBUFS
563c3268a9STrond Norbye#define SHUT_RDWR SD_BOTH
573c3268a9STrond Norbye#endif
583c3268a9STrond Norbye
593c3268a9STrond Norbye/* EAI_SYSTEM isn't defined anywhere... just set it to... 11? */
603c3268a9STrond Norbye#define EAI_SYSTEM 11
613c3268a9STrond Norbye
623c3268a9STrond Norbye/* Best effort mapping of functions to alternative functions */
633c3268a9STrond Norbye#define index(a,b) strchr(a,b)
643c3268a9STrond Norbye#define rindex(a,b) strrchr(a,b)
653c3268a9STrond Norbye#define random() rand()
663c3268a9STrond Norbye#define kill(a, b) while (false) {}
673c3268a9STrond Norbye#define fork() (-1)
683c3268a9STrond Norbye#define waitpid(a,b,c) (-1)
693c3268a9STrond Norbye#define fnmatch(a,b,c) (-1)
703c3268a9STrond Norbye#define sleep(a) Sleep(a*1000)
713c3268a9STrond Norbye
723c3268a9STrond Norbye#endif /* WIN32_WRAPPERS_H */
73