Inside Bitcoin
Opening the selected file…
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
1// Copyright (c) 2020-present The Bitcoin Core developers2// Distributed under the MIT software license, see the accompanying3// file COPYING or http://www.opensource.org/licenses/mit-license.php.5#include <bitcoin-build-config.h> // IWYU pragma: keep7#include <util/syserror.h>9#include <tinyformat.h>11#include <cstring>12#include <string>14#if defined(WIN32)15#include <windows.h>16#endif18std::string SysErrorString(int err)19{20char buf[1024];21/* Too bad there are three incompatible implementations of the22* thread-safe strerror. */23const char *s = nullptr;24#ifdef WIN3225if (strerror_s(buf, sizeof(buf), err) == 0) s = buf;26#else27#ifdef STRERROR_R_CHAR_P /* GNU variant can return a pointer outside the passed buffer */28s = strerror_r(err, buf, sizeof(buf));29#else /* POSIX variant always returns message in buffer */30if (strerror_r(err, buf, sizeof(buf)) == 0) s = buf;31#endif32#endif33if (s != nullptr) {34return strprintf("%s (%d)", s, err);35} else {36return strprintf("Unknown error (%d)", err);37}38}40#if defined(WIN32)41std::string Win32ErrorString(int err)42{43char buf[256];44buf[0] = 0;45if (FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_MAX_WIDTH_MASK,46nullptr, err, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),47buf, ARRAYSIZE(buf), nullptr)) {48return strprintf("%s (%d)", buf, err);49} else {50return strprintf("Unknown error (%d)", err);51}52}53#endif