Bitcoin ABC 0.26.3
P2P Digital Currency
Loading...
Searching...
No Matches
syserror.cpp
Go to the documentation of this file.
1// Copyright (c) 2020-2022 The Bitcoin Core developers
2// Distributed under the MIT software license, see the accompanying
3// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
5#if defined(HAVE_CONFIG_H)
6#include <config/bitcoin-config.h>
7#endif
8
9#include <tinyformat.h>
10#include <util/syserror.h>
11
12#include <cstring>
13
14std::string SysErrorString(int err) {
15 char buf[1024];
20 const char *s = nullptr;
21#ifdef WIN32
22 if (strerror_s(buf, sizeof(buf), err) == 0) {
23 s = buf;
24 }
25#else
26#ifdef STRERROR_R_CHAR_P
27 /* GNU variant can return a pointer outside the passed buffer */
28 s = strerror_r(err, buf, sizeof(buf));
29#else
30 /* POSIX variant always returns message in buffer */
31 if (strerror_r(err, buf, sizeof(buf)) == 0) {
32 s = buf;
33 }
34#endif
35#endif
36 if (s != nullptr) {
37 return strprintf("%s (%d)", s, err);
38 } else {
39 return strprintf("Unknown error (%d)", err);
40 }
41}
T GetRand(T nMax=std::numeric_limits< T >::max()) noexcept
Generate a uniform random integer of type T in the range [0..nMax) nMax defaults to std::numeric_limi...
Definition random.h:85
std::string SysErrorString(int err)
Return system error string from errno value.
Definition syserror.cpp:14
#define strprintf
Format arguments and return the string or write to given std::ostream (see tinyformat::format doc for...