Merge #12079: Improve prioritisetransaction test coverage
[bitcoinplatinum.git] / src / compat.h
blob65e9683e2fb66357fcc9ad88ceecd68dc2f95c3d
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2017 The Bitcoin Core developers
3 // Distributed under the MIT software license, see the accompanying
4 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
6 #ifndef BITCOIN_COMPAT_H
7 #define BITCOIN_COMPAT_H
9 #if defined(HAVE_CONFIG_H)
10 #include <config/bitcoin-config.h>
11 #endif
13 #ifdef WIN32
14 #ifdef _WIN32_WINNT
15 #undef _WIN32_WINNT
16 #endif
17 #define _WIN32_WINNT 0x0501
18 #ifndef WIN32_LEAN_AND_MEAN
19 #define WIN32_LEAN_AND_MEAN 1
20 #endif
21 #ifndef NOMINMAX
22 #define NOMINMAX
23 #endif
24 #ifdef FD_SETSIZE
25 #undef FD_SETSIZE // prevent redefinition compiler warning
26 #endif
27 #define FD_SETSIZE 1024 // max number of fds in fd_set
29 #include <winsock2.h> // Must be included before mswsock.h and windows.h
31 #include <mswsock.h>
32 #include <windows.h>
33 #include <ws2tcpip.h>
34 #include <stdint.h>
35 #else
36 #include <sys/fcntl.h>
37 #include <sys/mman.h>
38 #include <sys/select.h>
39 #include <sys/socket.h>
40 #include <sys/types.h>
41 #include <net/if.h>
42 #include <netinet/in.h>
43 #include <netinet/tcp.h>
44 #include <arpa/inet.h>
45 #include <ifaddrs.h>
46 #include <limits.h>
47 #include <netdb.h>
48 #include <unistd.h>
49 #endif
51 #ifndef WIN32
52 typedef unsigned int SOCKET;
53 #include <errno.h>
54 #define WSAGetLastError() errno
55 #define WSAEINVAL EINVAL
56 #define WSAEALREADY EALREADY
57 #define WSAEWOULDBLOCK EWOULDBLOCK
58 #define WSAEMSGSIZE EMSGSIZE
59 #define WSAEINTR EINTR
60 #define WSAEINPROGRESS EINPROGRESS
61 #define WSAEADDRINUSE EADDRINUSE
62 #define WSAENOTSOCK EBADF
63 #define INVALID_SOCKET (SOCKET)(~0)
64 #define SOCKET_ERROR -1
65 #endif
67 #ifdef WIN32
68 #ifndef S_IRUSR
69 #define S_IRUSR 0400
70 #define S_IWUSR 0200
71 #endif
72 #else
73 #define MAX_PATH 1024
74 #endif
75 #ifdef _MSC_VER
76 #if !defined(ssize_t)
77 #ifdef _WIN64
78 typedef int64_t ssize_t;
79 #else
80 typedef int32_t ssize_t;
81 #endif
82 #endif
83 #endif
85 #if HAVE_DECL_STRNLEN == 0
86 size_t strnlen( const char *start, size_t max_len);
87 #endif // HAVE_DECL_STRNLEN
89 bool static inline IsSelectableSocket(const SOCKET& s) {
90 #ifdef WIN32
91 return true;
92 #else
93 return (s < FD_SETSIZE);
94 #endif
97 #endif // BITCOIN_COMPAT_H