aboutsummaryrefslogtreecommitdiff
path: root/src/util.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/util.cpp')
-rw-r--r--src/util.cpp67
1 files changed, 33 insertions, 34 deletions
diff --git a/src/util.cpp b/src/util.cpp
index b76c173f90..51ccc94787 100644
--- a/src/util.cpp
+++ b/src/util.cpp
@@ -144,7 +144,7 @@ public:
// Securely erase the memory used by the PRNG
RAND_cleanup();
// Shutdown OpenSSL library multithreading support
- CRYPTO_set_locking_callback(NULL);
+ CRYPTO_set_locking_callback(nullptr);
// Clear the set of locks now to maintain symmetry with the constructor.
ppmutexOpenSSL.reset();
}
@@ -173,8 +173,8 @@ static boost::once_flag debugPrintInitFlag = BOOST_ONCE_INIT;
* the OS/libc. When the shutdown sequence is fully audited and
* tested, explicit destruction of these objects can be implemented.
*/
-static FILE* fileout = NULL;
-static boost::mutex* mutexDebugLog = NULL;
+static FILE* fileout = nullptr;
+static boost::mutex* mutexDebugLog = nullptr;
static std::list<std::string>* vMsgsBeforeOpenLog;
static int FileWriteStr(const std::string &str, FILE *fp)
@@ -184,7 +184,7 @@ static int FileWriteStr(const std::string &str, FILE *fp)
static void DebugPrintInit()
{
- assert(mutexDebugLog == NULL);
+ assert(mutexDebugLog == nullptr);
mutexDebugLog = new boost::mutex();
vMsgsBeforeOpenLog = new std::list<std::string>;
}
@@ -194,12 +194,12 @@ void OpenDebugLog()
boost::call_once(&DebugPrintInit, debugPrintInitFlag);
boost::mutex::scoped_lock scoped_lock(*mutexDebugLog);
- assert(fileout == NULL);
+ assert(fileout == nullptr);
assert(vMsgsBeforeOpenLog);
fs::path pathDebug = GetDataDir() / "debug.log";
fileout = fsbridge::fopen(pathDebug, "a");
if (fileout) {
- setbuf(fileout, NULL); // unbuffered
+ setbuf(fileout, nullptr); // unbuffered
// dump buffered messages from before we opened the log
while (!vMsgsBeforeOpenLog->empty()) {
FileWriteStr(vMsgsBeforeOpenLog->front(), fileout);
@@ -208,7 +208,7 @@ void OpenDebugLog()
}
delete vMsgsBeforeOpenLog;
- vMsgsBeforeOpenLog = NULL;
+ vMsgsBeforeOpenLog = nullptr;
}
struct CLogCategoryDesc
@@ -344,7 +344,7 @@ int LogPrintStr(const std::string &str)
boost::mutex::scoped_lock scoped_lock(*mutexDebugLog);
// buffer if we haven't opened the log yet
- if (fileout == NULL) {
+ if (fileout == nullptr) {
assert(vMsgsBeforeOpenLog);
ret = strTimestamped.length();
vMsgsBeforeOpenLog->push_back(strTimestamped);
@@ -355,8 +355,8 @@ int LogPrintStr(const std::string &str)
if (fReopenDebugLog) {
fReopenDebugLog = false;
fs::path pathDebug = GetDataDir() / "debug.log";
- if (fsbridge::freopen(pathDebug,"a",fileout) != NULL)
- setbuf(fileout, NULL); // unbuffered
+ if (fsbridge::freopen(pathDebug,"a",fileout) != nullptr)
+ setbuf(fileout, nullptr); // unbuffered
}
ret = FileWriteStr(strTimestamped, fileout);
@@ -419,49 +419,48 @@ void ArgsManager::ParseParameters(int argc, const char* const argv[])
}
}
-std::vector<std::string> ArgsManager::GetArgs(const std::string& strArg)
+std::vector<std::string> ArgsManager::GetArgs(const std::string& strArg) const
{
LOCK(cs_args);
- if (IsArgSet(strArg))
- return mapMultiArgs.at(strArg);
+ auto it = mapMultiArgs.find(strArg);
+ if (it != mapMultiArgs.end()) return it->second;
return {};
}
-bool ArgsManager::IsArgSet(const std::string& strArg)
+bool ArgsManager::IsArgSet(const std::string& strArg) const
{
LOCK(cs_args);
return mapArgs.count(strArg);
}
-std::string ArgsManager::GetArg(const std::string& strArg, const std::string& strDefault)
+std::string ArgsManager::GetArg(const std::string& strArg, const std::string& strDefault) const
{
LOCK(cs_args);
- if (mapArgs.count(strArg))
- return mapArgs[strArg];
+ auto it = mapArgs.find(strArg);
+ if (it != mapArgs.end()) return it->second;
return strDefault;
}
-int64_t ArgsManager::GetArg(const std::string& strArg, int64_t nDefault)
+int64_t ArgsManager::GetArg(const std::string& strArg, int64_t nDefault) const
{
LOCK(cs_args);
- if (mapArgs.count(strArg))
- return atoi64(mapArgs[strArg]);
+ auto it = mapArgs.find(strArg);
+ if (it != mapArgs.end()) return atoi64(it->second);
return nDefault;
}
-bool ArgsManager::GetBoolArg(const std::string& strArg, bool fDefault)
+bool ArgsManager::GetBoolArg(const std::string& strArg, bool fDefault) const
{
LOCK(cs_args);
- if (mapArgs.count(strArg))
- return InterpretBool(mapArgs[strArg]);
+ auto it = mapArgs.find(strArg);
+ if (it != mapArgs.end()) return InterpretBool(it->second);
return fDefault;
}
bool ArgsManager::SoftSetArg(const std::string& strArg, const std::string& strValue)
{
LOCK(cs_args);
- if (mapArgs.count(strArg))
- return false;
+ if (IsArgSet(strArg)) return false;
ForceSetArg(strArg, strValue);
return true;
}
@@ -478,8 +477,7 @@ void ArgsManager::ForceSetArg(const std::string& strArg, const std::string& strV
{
LOCK(cs_args);
mapArgs[strArg] = strValue;
- mapMultiArgs[strArg].clear();
- mapMultiArgs[strArg].push_back(strValue);
+ mapMultiArgs[strArg] = {strValue};
}
@@ -503,7 +501,7 @@ static std::string FormatException(const std::exception* pex, const char* pszThr
{
#ifdef WIN32
char pszModule[MAX_PATH] = "";
- GetModuleFileNameA(NULL, pszModule, sizeof(pszModule));
+ GetModuleFileNameA(nullptr, pszModule, sizeof(pszModule));
#else
const char* pszModule = "bitcoin";
#endif
@@ -534,7 +532,7 @@ fs::path GetDefaultDataDir()
#else
fs::path pathRet;
char* pszHome = getenv("HOME");
- if (pszHome == NULL || strlen(pszHome) == 0)
+ if (pszHome == nullptr || strlen(pszHome) == 0)
pathRet = fs::path("/");
else
pathRet = fs::path(pszHome);
@@ -564,8 +562,8 @@ const fs::path &GetDataDir(bool fNetSpecific)
if (!path.empty())
return path;
- if (IsArgSet("-datadir")) {
- path = fs::system_complete(GetArg("-datadir", ""));
+ if (gArgs.IsArgSet("-datadir")) {
+ path = fs::system_complete(gArgs.GetArg("-datadir", ""));
if (!fs::is_directory(path)) {
path = "";
return path;
@@ -627,7 +625,7 @@ void ArgsManager::ReadConfigFile(const std::string& confPath)
#ifndef WIN32
fs::path GetPidFile()
{
- fs::path pathPidFile(GetArg("-pid", BITCOIN_PID_FILENAME));
+ fs::path pathPidFile(gArgs.GetArg("-pid", BITCOIN_PID_FILENAME));
if (!pathPidFile.is_complete()) pathPidFile = GetDataDir() / pathPidFile;
return pathPidFile;
}
@@ -791,7 +789,7 @@ void ShrinkDebugFile()
fclose(file);
}
}
- else if (file != NULL)
+ else if (file != nullptr)
fclose(file);
}
@@ -800,7 +798,7 @@ fs::path GetSpecialFolderPath(int nFolder, bool fCreate)
{
char pszPath[MAX_PATH] = "";
- if(SHGetSpecialFolderPathA(NULL, pszPath, nFolder, fCreate))
+ if(SHGetSpecialFolderPathA(nullptr, pszPath, nFolder, fCreate))
{
return fs::path(pszPath);
}
@@ -812,6 +810,7 @@ fs::path GetSpecialFolderPath(int nFolder, bool fCreate)
void runCommand(const std::string& strCommand)
{
+ if (strCommand.empty()) return;
int nErr = ::system(strCommand.c_str());
if (nErr)
LogPrintf("runCommand error: system(%s) returned %d\n", strCommand, nErr);