6#include <bitcoin-build-config.h>
24#ifdef HAVE_MALLOPT_ARENA_MAX
46 std::string escaped = arg;
48 return "'" + escaped +
"'";
53void runCommand(
const std::string& strCommand)
55 if (strCommand.empty())
return;
57 int nErr = ::system(strCommand.c_str());
59 int nErr = ::_wsystem(std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>,
wchar_t>().from_bytes(strCommand).c_str());
62 LogPrintf(
"runCommand error: system(%s) returned %d\n", strCommand, nErr);
68#ifdef HAVE_MALLOPT_ARENA_MAX
74 if (
sizeof(
void*) == 4) {
75 mallopt(M_ARENA_MAX, 1);
80#if !defined(WIN32) && !defined(__APPLE__) && !defined(__FreeBSD__) && !defined(__OpenBSD__) && !defined(__NetBSD__)
83 }
catch (
const std::runtime_error&) {
84 setenv(
"LC_ALL",
"C.UTF-8", 1);
87 assert(GetACP() == CP_UTF8);
89 SetConsoleCP(CP_UTF8);
90 SetConsoleOutputCP(CP_UTF8);
94 constexpr mode_t private_umask = 0077;
104 int ret = WSAStartup(MAKEWORD(2,2), &wsadata);
105 if (
ret != NO_ERROR || LOBYTE(wsadata.wVersion ) != 2 || HIBYTE(wsadata.wVersion) != 2)
113 return std::thread::hardware_concurrency();
118 [[maybe_unused]]
auto clamp{[](uint64_t v) {
return size_t(std::min(v, uint64_t{std::numeric_limits<size_t>::max()})); }};
120 if (MEMORYSTATUSEX
m{}; (
m.dwLength =
sizeof(
m), GlobalMemoryStatusEx(&
m)))
return clamp(
m.ullTotalPhys);
121#elif defined(__APPLE__) || \
122 defined(__FreeBSD__) || \
123 defined(__NetBSD__) || \
124 defined(__OpenBSD__) || \
125 defined(__illumos__) || \
127 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.