X-Git-Url: https://git.novaco.in/?a=blobdiff_plain;f=src%2Futil.cpp;h=a40771417b2ba28b58fe9a51eee1503266e7d54f;hb=23e7583a8c9a0dcee9cbbf3be8bfc453298773f0;hp=19e48d3bd9d1d23563080bede237af92bb33a87b;hpb=a6fa147c8d2dabe9f226bb8e1bc5904718ef1fc1;p=novacoin.git diff --git a/src/util.cpp b/src/util.cpp index 19e48d3..a407714 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -1,7 +1,7 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2012 The Bitcoin developers // Distributed under the MIT/X11 software license, see the accompanying -// file license.txt or http://www.opensource.org/licenses/mit-license.php. +// file COPYING or http://www.opensource.org/licenses/mit-license.php. #include "util.h" #include "strlcpy.h" @@ -26,6 +26,7 @@ namespace boost { #include #include #include +#include #include #include @@ -174,6 +175,12 @@ int GetRandInt(int nMax) return GetRand(nMax); } +uint256 GetRandHash() +{ + uint256 hash; + RAND_bytes((unsigned char*)&hash, sizeof(hash)); + return hash; +} @@ -209,6 +216,8 @@ inline int OutputDebugStringF(const char* pszFormat, ...) if (fileout) { static bool fStartedNewLine = true; + static boost::mutex mutexDebugLog; + boost::mutex::scoped_lock scoped_lock(mutexDebugLog); // Debug print useful for profiling if (fLogTimestamps && fStartedNewLine) @@ -252,7 +261,7 @@ inline int OutputDebugStringF(const char* pszFormat, ...) *pend = '\0'; char* p1 = pszBuffer; char* p2; - while (p2 = strchr(p1, '\n')) + while ((p2 = strchr(p1, '\n'))) { p2++; char c = *p2; @@ -283,7 +292,7 @@ int my_snprintf(char* buffer, size_t limit, const char* format, ...) va_start(arg_ptr, format); int ret = _vsnprintf(buffer, limit, format, arg_ptr); va_end(arg_ptr); - if (ret < 0 || ret >= limit) + if (ret < 0 || ret >= (int)limit) { ret = limit - 1; buffer[limit-1] = 0; @@ -425,7 +434,7 @@ bool ParseMoney(const char* pszIn, int64& nRet) } -static char phexdigit[256] = +static signed char phexdigit[256] = { -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, @@ -461,12 +470,12 @@ vector ParseHex(const char* psz) { while (isspace(*psz)) psz++; - char c = phexdigit[(unsigned char)*psz++]; - if (c == (char)-1) + signed char c = phexdigit[(unsigned char)*psz++]; + if (c == (signed char)-1) break; unsigned char n = (c << 4); c = phexdigit[(unsigned char)*psz++]; - if (c == (char)-1) + if (c == (signed char)-1) break; n |= c; vch.push_back(n); @@ -843,7 +852,7 @@ boost::filesystem::path GetDefaultDataDir() #ifdef MAC_OSX // Mac pathRet /= "Library/Application Support"; - filesystem::create_directory(pathRet); + fs::create_directory(pathRet); return pathRet / "Bitcoin"; #else // Unix @@ -870,7 +879,11 @@ const boost::filesystem::path &GetDataDir(bool fNetSpecific) LOCK(csPathCached); if (mapArgs.count("-datadir")) { - path = mapArgs["-datadir"]; + path = fs::system_complete(mapArgs["-datadir"]); + if (!fs::is_directory(path)) { + path = ""; + return path; + } } else { path = GetDefaultDataDir(); } @@ -892,7 +905,7 @@ boost::filesystem::path GetConfigFile() return pathConfigFile; } -bool ReadConfigFile(map& mapSettingsRet, +void ReadConfigFile(map& mapSettingsRet, map >& mapMultiSettingsRet) { namespace fs = boost::filesystem; @@ -900,7 +913,7 @@ bool ReadConfigFile(map& mapSettingsRet, fs::ifstream streamConfig(GetConfigFile()); if (!streamConfig.good()) - return true; // No bitcoin.conf file is OK + return; // No bitcoin.conf file is OK set setOptions; setOptions.insert("*"); @@ -917,7 +930,6 @@ bool ReadConfigFile(map& mapSettingsRet, } mapMultiSettingsRet[strKey].push_back(it->value[0]); } - return true; } boost::filesystem::path GetPidFile()