aboutsummaryrefslogtreecommitdiff
path: root/src/util/syserror.h
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/syserror.h
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/syserror.h')
-rw-r--r--src/util/syserror.h16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/util/syserror.h b/src/util/syserror.h
new file mode 100644
index 0000000000..a54ba553ee
--- /dev/null
+++ b/src/util/syserror.h
@@ -0,0 +1,16 @@
+// Copyright (c) 2010-2022 The Bitcoin Core developers
+// Distributed under the MIT software license, see the accompanying
+// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+
+#ifndef BITCOIN_UTIL_SYSERROR_H
+#define BITCOIN_UTIL_SYSERROR_H
+
+#include <string>
+
+/** Return system error string from errno value. Use this instead of
+ * std::strerror, which is not thread-safe. For network errors use
+ * NetworkErrorString from sock.h instead.
+ */
+std::string SysErrorString(int err);
+
+#endif // BITCOIN_UTIL_SYSERROR_H