6#include <bitcoin-build-config.h>
23#ifdef HAVE_MALLOPT_ARENA_MAX
45 std::string escaped = arg;
47 return "'" + escaped +
"'";
52void runCommand(
const std::string& strCommand)
54 if (strCommand.empty())
return;
56 int nErr = ::system(strCommand.c_str());
58 int nErr = ::_wsystem(std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>,
wchar_t>().from_bytes(strCommand).c_str());
61 LogPrintf(
"runCommand error: system(%s) returned %d\n", strCommand, nErr);
67#ifdef HAVE_MALLOPT_ARENA_MAX
73 if (
sizeof(
void*) == 4) {
74 mallopt(M_ARENA_MAX, 1);
79#if !defined(WIN32) && !defined(__APPLE__) && !defined(__FreeBSD__) && !defined(__OpenBSD__) && !defined(__NetBSD__)
82 }
catch (
const std::runtime_error&) {
83 setenv(
"LC_ALL",
"C.UTF-8", 1);
87 SetConsoleCP(CP_UTF8);
88 SetConsoleOutputCP(CP_UTF8);
92 constexpr mode_t private_umask = 0077;
102 int ret = WSAStartup(MAKEWORD(2,2), &wsadata);
103 if (
ret != NO_ERROR || LOBYTE(wsadata.wVersion ) != 2 || HIBYTE(wsadata.wVersion) != 2)
111 return std::thread::hardware_concurrency();
116 [[maybe_unused]]
auto clamp{[](uint64_t v) {
return size_t(std::min(v, uint64_t{std::numeric_limits<size_t>::max()})); }};
118 if (MEMORYSTATUSEX
m{}; (
m.dwLength =
sizeof(
m), GlobalMemoryStatusEx(&
m)))
return clamp(
m.ullTotalPhys);
119#elif defined(__APPLE__) || \
120 defined(__FreeBSD__) || \
121 defined(__NetBSD__) || \
122 defined(__OpenBSD__) || \
123 defined(__illumos__) || \
125 if (
long p{sysconf(_SC_PHYS_PAGES)},
s{sysconf(_SC_PAGESIZE)}; p > 0 &&
s > 0)
return clamp(1ULL * p *
s);
std::optional< size_t > GetTotalRAM()
Return the total RAM available on the current system, if detectable.
const int64_t nStartupTime
int GetNumCores()
Return the number of cores available on the current system.
std::string ShellEscape(const std::string &arg)
void ReplaceAll(std::string &in_out, const std::string &search, const std::string &substitute)
int64_t GetTime()
DEPRECATED Use either ClockType::now() or Now<TimePointType>() if a cast is needed.