X-Git-Url: https://git.novaco.in/?a=blobdiff_plain;f=src%2Futil.h;h=7035091508422f378a9a69f8cb105aacf2c288ec;hb=f18b69e03e97616e755e1aa718b38e62c3a643cf;hp=c6b5dea91c32f650bd3dc15a93c844efeff2b7b5;hpb=33118dc3f360ed4c8062929fc02fc18a30582ec0;p=novacoin.git diff --git a/src/util.h b/src/util.h index c6b5dea..7035091 100644 --- a/src/util.h +++ b/src/util.h @@ -24,8 +24,6 @@ #include #include #include -#include -#include #endif #include @@ -48,12 +46,6 @@ static const int64_t CENT = 10000; #define END(a) ((char*)&((&(a))[1])) #define UBEGIN(a) ((unsigned char*)&(a)) #define UEND(a) ((unsigned char*)&((&(a))[1])) -#define ARRAYLEN(array) (sizeof(array)/sizeof((array)[0])) - -#define UVOIDBEGIN(a) ((void*)&(a)) -#define CVOIDBEGIN(a) ((const void*)&(a)) -#define UINTBEGIN(a) ((uint32_t*)&(a)) -#define CUINTBEGIN(a) ((const uint32_t*)&(a)) #ifndef THROW_WITH_STACKTRACE #define THROW_WITH_STACKTRACE(exception) \ @@ -123,7 +115,9 @@ T* alignup(T* p) #define MAX_PATH 1024 inline void Sleep(int64_t n) { - this_thread::sleep_for(std::chrono::milliseconds(n)); + /*Boost has a year 2038 problem— if the request sleep time is past epoch+2^31 seconds the sleep returns instantly. + So we clamp our sleeps here to 10 years and hope that boost is fixed by 2028.*/ + boost::thread::sleep(boost::get_system_time() + boost::posix_time::milliseconds(n>315576000000LL?315576000000LL:n)); } #endif @@ -198,8 +192,8 @@ void ParseString(const std::string& str, char c, std::vector& v); std::string FormatMoney(int64_t n, bool fPlus=false); bool ParseMoney(const std::string& str, int64_t& nRet); bool ParseMoney(const char* pszIn, int64_t& nRet); -std::vector ParseHex(const char* psz); -std::vector ParseHex(const std::string& str); +std::vector ParseHex(const char *str); +inline std::vector ParseHex(const std::string& str) { return ParseHex(str.c_str()); } bool IsHex(const std::string& str); std::vector DecodeBase64(const char* p, bool* pfInvalid = NULL); std::string DecodeBase64(const std::string& str); @@ -234,6 +228,7 @@ void ShrinkDebugFile(); int GetRandInt(int nMax); uint64_t GetRand(uint64_t nMax); uint256 GetRandHash(); +void FillRand(uint8_t *buffer, size_t nCount); int64_t GetTime(); int64_t GetTimeMillis(); int64_t GetTimeMicros(); @@ -250,36 +245,19 @@ void runCommand(std::string strCommand); - - - - inline std::string i64tostr(int64_t n) { return strprintf("%" PRId64, n); } -inline std::string itostr(int n) -{ - return strprintf("%d", n); -} - -inline int64_t atoi64(const char* psz) +inline int64_t strtoll(const char* psz) { -#ifdef _MSC_VER - return _atoi64(psz); -#else return strtoll(psz, NULL, 10); -#endif } -inline int64_t atoi64(const std::string& str) +inline int64_t strtoll(const std::string& str) { -#ifdef _MSC_VER - return _atoi64(str.c_str()); -#else return strtoll(str.c_str(), NULL, 10); -#endif } inline int32_t strtol(const char* psz) @@ -317,11 +295,6 @@ inline int64_t roundint64(double d) return (int64_t)(d > 0 ? d + 0.5 : d - 0.5); } -inline int64_t abs64(int64_t n) -{ - return (n >= 0 ? n : -n); -} - inline std::string leftTrim(std::string src, char chr) { std::string::size_type pos = src.find_first_not_of(chr, 0); @@ -382,14 +355,12 @@ inline int64_t GetPerformanceCounter() inline int64_t GetTimeMillis() { - return (boost::posix_time::microsec_clock::universal_time() - - boost::posix_time::ptime(boost::gregorian::date(1970,1,1))).total_milliseconds(); + return std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch()).count(); } inline int64_t GetTimeMicros() { - return (boost::posix_time::microsec_clock::universal_time() - - boost::posix_time::ptime(boost::gregorian::date(1970,1,1))).total_microseconds(); + return std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch()).count(); } std::string DateTimeStrFormat(const char* pszFormat, int64_t nTime);