Skip to content

Commit

Permalink
Merge pull request #2165 from catchorg/devel-gmtime-fixup
Browse files Browse the repository at this point in the history
Use gmtime_r instead of gmtime when compiling for posixy platforms
  • Loading branch information
horenmar committed Jan 27, 2021
2 parents b435e39 + 4775407 commit 2dbe63a
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions src/catch2/reporters/catch_reporter_junit.cpp
Expand Up @@ -22,28 +22,22 @@ namespace Catch {

namespace {
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;
std::time(&rawtime);
auto const timeStampSize = sizeof("2017-01-16T17:06:45Z");

#ifdef _MSC_VER
std::tm timeInfo = {};
#ifdef _MSC_VER
gmtime_s(&timeInfo, &rawtime);
#else
std::tm* timeInfo;
timeInfo = std::gmtime(&rawtime);
gmtime_r(&rawtime, &timeInfo);
#endif

auto const timeStampSize = sizeof("2017-01-16T17:06:45Z");
char timeStamp[timeStampSize];
const char * const fmt = "%Y-%m-%dT%H:%M:%SZ";

#ifdef _MSC_VER
std::strftime(timeStamp, timeStampSize, fmt, &timeInfo);
#else
std::strftime(timeStamp, timeStampSize, fmt, timeInfo);
#endif

return std::string(timeStamp);
}

Expand Down

0 comments on commit 2dbe63a

Please sign in to comment.