aboutsummaryrefslogtreecommitdiff
path: root/src/util/sock.cpp
diff options
context:
space:
mode:
authorlaanwj <126646+laanwj@users.noreply.github.com>2022-04-20 16:17:19 +0200
committerlaanwj <126646+laanwj@users.noreply.github.com>2022-04-28 10:24:06 +0200
commit46971c6dbfbc39ebbc74ab1ed8c00edc12859373 (patch)
tree9b8e249e986116f4490cacf2e9c8439b2066b8a7 /src/util/sock.cpp
parent4381681e554d9bf10ef1ac43cede9cfa10bfb439 (diff)
downloadbitcoin-46971c6dbfbc39ebbc74ab1ed8c00edc12859373.tar.xz
util: Replace non-threadsafe strerror
Some uses of non-threadsafe `strerror` have snuck into the code since they were removed in #4152. Add a wrapper `SysErrorString` for thread-safe strerror alternatives and replace all uses of `strerror` with this.
Diffstat (limited to 'src/util/sock.cpp')
-rw-r--r--src/util/sock.cpp16
1 files changed, 3 insertions, 13 deletions
diff --git a/src/util/sock.cpp b/src/util/sock.cpp
index b5c1e28294..3579af4458 100644
--- a/src/util/sock.cpp
+++ b/src/util/sock.cpp
@@ -7,6 +7,7 @@
#include <threadinterrupt.h>
#include <tinyformat.h>
#include <util/sock.h>
+#include <util/syserror.h>
#include <util/system.h>
#include <util/time.h>
@@ -344,19 +345,8 @@ std::string NetworkErrorString(int err)
#else
std::string NetworkErrorString(int err)
{
- char buf[256];
- buf[0] = 0;
- /* Too bad there are two incompatible implementations of the
- * thread-safe strerror. */
- const char *s;
-#ifdef STRERROR_R_CHAR_P /* GNU variant can return a pointer outside the passed buffer */
- s = strerror_r(err, buf, sizeof(buf));
-#else /* POSIX variant always returns message in buffer */
- s = buf;
- if (strerror_r(err, buf, sizeof(buf)))
- buf[0] = 0;
-#endif
- return strprintf("%s (%d)", s, err);
+ // On BSD sockets implementations, NetworkErrorString is the same as SysErrorString.
+ return SysErrorString(err);
}
#endif