Skip to content

Commit 5c82ca3

Browse files
author
MacroFake
committed
Merge bitcoin/bitcoin#25493: compat: document code in compat.h
f7dc992 compat: document redefining ssize_t when using MSVC (fanquake) 3be7ee7 compat: document error-code mapping (fanquake) 3f1d2fb compat: document sockopt_arg_type definition (fanquake) fb6db6f compat: document S_I* defines when building for Windows (fanquake) 203e682 compat: extract and document MAX_PATH (fanquake) b63ddb7 compat: remove unused WSA* definitions (fanquake) 7c3df5e compat: document FD_SETSIZE redefinition for WIN32 (fanquake) cc7b2fd refactor: move compat.h into compat/ (fanquake) Pull request description: Move `compat.h` into `compat/`, and document what is in there. ACKs for top commit: vasild: ACK f7dc992 hebasto: re-ACK f7dc992 Tree-SHA512: 9e7e90261a97eae7998ef8d140d8ffab504cccf19abb44ca253d8919a067bb01e3fa9876a44194a1a9fb08a4b0489376844f827d8a27aa66c0f99c60ad5d7041
2 parents 1eedde1 + f7dc992 commit 5c82ca3

30 files changed

+56
-47
lines changed

src/Makefile.am

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,9 @@ BITCOIN_CORE_H = \
133133
clientversion.h \
134134
coins.h \
135135
common/bloom.h \
136-
compat.h \
137136
compat/assumptions.h \
138137
compat/byteswap.h \
138+
compat/compat.h \
139139
compat/cpuid.h \
140140
compat/endian.h \
141141
compressor.h \

src/bitcoin-cli.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
#include <chainparamsbase.h>
1111
#include <clientversion.h>
12-
#include <compat.h>
12+
#include <compat/compat.h>
1313
#include <compat/stdin.h>
1414
#include <policy/feerate.h>
1515
#include <rpc/client.h>

src/bitcoin-tx.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
#include <clientversion.h>
1010
#include <coins.h>
11-
#include <compat.h>
11+
#include <compat/compat.h>
1212
#include <consensus/amount.h>
1313
#include <consensus/consensus.h>
1414
#include <core_io.h>

src/bitcoin-util.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#include <chainparams.h>
1212
#include <chainparamsbase.h>
1313
#include <clientversion.h>
14-
#include <compat.h>
14+
#include <compat/compat.h>
1515
#include <core_io.h>
1616
#include <streams.h>
1717
#include <util/system.h>

src/bitcoin-wallet.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include <chainparams.h>
1010
#include <chainparamsbase.h>
1111
#include <clientversion.h>
12-
#include <compat.h>
12+
#include <compat/compat.h>
1313
#include <interfaces/init.h>
1414
#include <key.h>
1515
#include <logging.h>

src/bitcoind.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
#include <chainparams.h>
1111
#include <clientversion.h>
12-
#include <compat.h>
12+
#include <compat/compat.h>
1313
#include <init.h>
1414
#include <interfaces/chain.h>
1515
#include <interfaces/init.h>

src/compat.h renamed to src/compat/compat.h

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,24 @@
33
// Distributed under the MIT software license, see the accompanying
44
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
55

6-
#ifndef BITCOIN_COMPAT_H
7-
#define BITCOIN_COMPAT_H
6+
#ifndef BITCOIN_COMPAT_COMPAT_H
7+
#define BITCOIN_COMPAT_COMPAT_H
88

99
#if defined(HAVE_CONFIG_H)
1010
#include <config/bitcoin-config.h>
1111
#endif
1212

13+
// Windows defines FD_SETSIZE to 64 (see _fd_types.h in mingw-w64),
14+
// which is too small for our usage, but allows us to redefine it safely.
15+
// We redefine it to be 1024, to match glibc, see typesizes.h.
1316
#ifdef WIN32
1417
#ifdef FD_SETSIZE
15-
#undef FD_SETSIZE // prevent redefinition compiler warning
18+
#undef FD_SETSIZE
1619
#endif
17-
#define FD_SETSIZE 1024 // max number of fds in fd_set
20+
#define FD_SETSIZE 1024
1821
#include <winsock2.h>
1922
#include <ws2tcpip.h>
20-
#include <stdint.h>
23+
#include <cstdint>
2124
#else
2225
#include <fcntl.h>
2326
#include <sys/mman.h>
@@ -34,49 +37,54 @@
3437
#include <unistd.h>
3538
#endif
3639

40+
// We map Linux / BSD error functions and codes, to the equivalent
41+
// Windows definitions, and use the WSA* names throughout our code.
42+
// Note that glibc defines EWOULDBLOCK as EAGAIN (see errno.h).
3743
#ifndef WIN32
3844
typedef unsigned int SOCKET;
39-
#include <errno.h>
45+
#include <cerrno>
4046
#define WSAGetLastError() errno
4147
#define WSAEINVAL EINVAL
42-
#define WSAEALREADY EALREADY
4348
#define WSAEWOULDBLOCK EWOULDBLOCK
4449
#define WSAEAGAIN EAGAIN
4550
#define WSAEMSGSIZE EMSGSIZE
4651
#define WSAEINTR EINTR
4752
#define WSAEINPROGRESS EINPROGRESS
4853
#define WSAEADDRINUSE EADDRINUSE
49-
#define WSAENOTSOCK EBADF
5054
#define INVALID_SOCKET (SOCKET)(~0)
5155
#define SOCKET_ERROR -1
5256
#else
53-
#ifndef WSAEAGAIN
57+
// WSAEAGAIN doesn't exist on Windows
5458
#ifdef EAGAIN
5559
#define WSAEAGAIN EAGAIN
5660
#else
5761
#define WSAEAGAIN WSAEWOULDBLOCK
5862
#endif
5963
#endif
60-
#endif
6164

65+
// Windows doesn't define S_IRUSR or S_IWUSR. We define both
66+
// here, with the same values as glibc (see stat.h).
6267
#ifdef WIN32
6368
#ifndef S_IRUSR
6469
#define S_IRUSR 0400
6570
#define S_IWUSR 0200
6671
#endif
67-
#else
72+
#endif
73+
74+
// Windows defines MAX_PATH as it's maximum path length.
75+
// We define MAX_PATH for use on non-Windows systems.
76+
#ifndef WIN32
6877
#define MAX_PATH 1024
6978
#endif
79+
80+
// ssize_t is POSIX, and not present when using MSVC.
7081
#ifdef _MSC_VER
71-
#if !defined(ssize_t)
72-
#ifdef _WIN64
73-
typedef int64_t ssize_t;
74-
#else
75-
typedef int32_t ssize_t;
76-
#endif
77-
#endif
82+
#include <BaseTsd.h>
83+
typedef SSIZE_T ssize_t;
7884
#endif
7985

86+
// The type of the option value passed to getsockopt & setsockopt
87+
// differs between Windows and non-Windows.
8088
#ifndef WIN32
8189
typedef void* sockopt_arg_type;
8290
#else
@@ -119,4 +127,4 @@ bool static inline IsSelectableSocket(const SOCKET& s) {
119127
#define MSG_DONTWAIT 0
120128
#endif
121129

122-
#endif // BITCOIN_COMPAT_H
130+
#endif // BITCOIN_COMPAT_COMPAT_H

src/httpserver.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include <httpserver.h>
1010

1111
#include <chainparamsbase.h>
12-
#include <compat.h>
12+
#include <compat/compat.h>
1313
#include <netbase.h>
1414
#include <node/interface_ui.h>
1515
#include <rpc/protocol.h> // For HTTP status codes

src/i2p.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
44

55
#include <chainparams.h>
6-
#include <compat.h>
6+
#include <compat/compat.h>
77
#include <compat/endian.h>
88
#include <crypto/sha256.h>
99
#include <fs.h>

src/i2p.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#ifndef BITCOIN_I2P_H
66
#define BITCOIN_I2P_H
77

8-
#include <compat.h>
8+
#include <compat/compat.h>
99
#include <fs.h>
1010
#include <netaddress.h>
1111
#include <sync.h>

0 commit comments

Comments
 (0)