build: Detect gmtime_* definitions via configure

This improves the portability of the codebase and fixes compilation
with mingw-w64 7.0+.

Co-authored-by: fanquake <fanquake@gmail.com>
This commit is contained in:
Ben Woosley
2020-03-18 15:23:25 -07:00
committed by fanquake
parent 41fa2926d8
commit a46484c8b3
2 changed files with 23 additions and 6 deletions

View File

@@ -78,10 +78,10 @@ int64_t GetSystemTimeInSeconds()
std::string FormatISO8601DateTime(int64_t nTime) {
struct tm ts;
time_t time_val = nTime;
#ifdef _MSC_VER
if (gmtime_s(&ts, &time_val) != 0) {
#else
#ifdef HAVE_GMTIME_R
if (gmtime_r(&time_val, &ts) == nullptr) {
#else
if (gmtime_s(&ts, &time_val) != 0) {
#endif
return {};
}
@@ -91,10 +91,10 @@ std::string FormatISO8601DateTime(int64_t nTime) {
std::string FormatISO8601Date(int64_t nTime) {
struct tm ts;
time_t time_val = nTime;
#ifdef _MSC_VER
if (gmtime_s(&ts, &time_val) != 0) {
#else
#ifdef HAVE_GMTIME_R
if (gmtime_r(&time_val, &ts) == nullptr) {
#else
if (gmtime_s(&ts, &time_val) != 0) {
#endif
return {};
}