mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-22 21:36:11 +01:00
Use gmtime_r instead of gmtime when compiling for posixy platforms
This commit is contained in:
parent
b435e391c4
commit
477540760a
@ -22,28 +22,22 @@ namespace Catch {
|
|||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
std::string getCurrentTimestamp() {
|
std::string getCurrentTimestamp() {
|
||||||
// Beware, this is not reentrant because of backward compatibility issues
|
|
||||||
// Also, UTC only, again because of backward compatibility (%z is C++11)
|
|
||||||
time_t rawtime;
|
time_t rawtime;
|
||||||
std::time(&rawtime);
|
std::time(&rawtime);
|
||||||
auto const timeStampSize = sizeof("2017-01-16T17:06:45Z");
|
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
|
||||||
std::tm timeInfo = {};
|
std::tm timeInfo = {};
|
||||||
|
#ifdef _MSC_VER
|
||||||
gmtime_s(&timeInfo, &rawtime);
|
gmtime_s(&timeInfo, &rawtime);
|
||||||
#else
|
#else
|
||||||
std::tm* timeInfo;
|
gmtime_r(&rawtime, &timeInfo);
|
||||||
timeInfo = std::gmtime(&rawtime);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
auto const timeStampSize = sizeof("2017-01-16T17:06:45Z");
|
||||||
char timeStamp[timeStampSize];
|
char timeStamp[timeStampSize];
|
||||||
const char * const fmt = "%Y-%m-%dT%H:%M:%SZ";
|
const char * const fmt = "%Y-%m-%dT%H:%M:%SZ";
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
|
||||||
std::strftime(timeStamp, timeStampSize, fmt, &timeInfo);
|
std::strftime(timeStamp, timeStampSize, fmt, &timeInfo);
|
||||||
#else
|
|
||||||
std::strftime(timeStamp, timeStampSize, fmt, timeInfo);
|
|
||||||
#endif
|
|
||||||
return std::string(timeStamp);
|
return std::string(timeStamp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user