mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-03-05 14:06:27 -05:00

Follow-up for PR #30856, commit 0dd66251
.
-BEGIN VERIFY SCRIPT-
sed -i "s|config/bitcoin-config\.h|bitcoin-build-config.h|g" $(git grep -l config/bitcoin-config\.h)
sed -i "s|bitcoin-config\.h|bitcoin-build-config.h|g" $(git grep -l "bitcoin-config\.h" ./src ./test ./cmake)
git mv ./cmake/bitcoin-config.h.in ./cmake/bitcoin-build-config.h.in
-END VERIFY SCRIPT-
57 lines
1.6 KiB
C++
57 lines
1.6 KiB
C++
// Copyright (c) 2020-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.
|
|
|
|
#include <bitcoin-build-config.h> // IWYU pragma: keep
|
|
|
|
#include <tinyformat.h>
|
|
#include <util/syserror.h>
|
|
|
|
#include <cstring>
|
|
#include <string>
|
|
|
|
#if defined(WIN32)
|
|
#include <windows.h>
|
|
#include <locale>
|
|
#include <codecvt>
|
|
#endif
|
|
|
|
std::string SysErrorString(int err)
|
|
{
|
|
char buf[1024];
|
|
/* Too bad there are three incompatible implementations of the
|
|
* thread-safe strerror. */
|
|
const char *s = nullptr;
|
|
#ifdef WIN32
|
|
if (strerror_s(buf, sizeof(buf), err) == 0) s = buf;
|
|
#else
|
|
#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 */
|
|
if (strerror_r(err, buf, sizeof(buf)) == 0) s = buf;
|
|
#endif
|
|
#endif
|
|
if (s != nullptr) {
|
|
return strprintf("%s (%d)", s, err);
|
|
} else {
|
|
return strprintf("Unknown error (%d)", err);
|
|
}
|
|
}
|
|
|
|
#if defined(WIN32)
|
|
std::string Win32ErrorString(int err)
|
|
{
|
|
wchar_t buf[256];
|
|
buf[0] = 0;
|
|
if(FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_MAX_WIDTH_MASK,
|
|
nullptr, err, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
|
|
buf, ARRAYSIZE(buf), nullptr))
|
|
{
|
|
return strprintf("%s (%d)", std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>,wchar_t>().to_bytes(buf), err);
|
|
}
|
|
else
|
|
{
|
|
return strprintf("Unknown error (%d)", err);
|
|
}
|
|
}
|
|
#endif
|