mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-12-08 03:33:32 +01:00
Replace non-threadsafe gmtime and setlocale
Make DateTimeStrFormat use boost::posix_time. Also re-enable the util_DateTimeStrFormat tests, as they are no longer platform specific.
This commit is contained in:
12
src/util.cpp
12
src/util.cpp
@@ -14,6 +14,8 @@
|
||||
|
||||
#include <stdarg.h>
|
||||
|
||||
#include <boost/date_time/posix_time/posix_time.hpp>
|
||||
|
||||
#ifndef WIN32
|
||||
// for posix_fallocate
|
||||
#ifdef __linux_
|
||||
@@ -1400,3 +1402,13 @@ void SetupEnvironment()
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
std::string DateTimeStrFormat(const char* pszFormat, int64_t nTime)
|
||||
{
|
||||
// std::locale takes ownership of the pointer
|
||||
std::locale loc(std::locale::classic(), new boost::posix_time::time_facet(pszFormat));
|
||||
std::stringstream ss;
|
||||
ss.imbue(loc);
|
||||
ss << boost::posix_time::from_time_t(nTime);
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user