Skip to content

Commit

Permalink
util: fix compilation with mingw-w64 7.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Fuzzbawls committed Apr 23, 2021
1 parent 25b41bb commit 0f750ca
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 12 deletions.
17 changes: 17 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -865,6 +865,22 @@ if test "x$use_thread_local" = xyes || { test "x$use_thread_local" = xauto && te
LDFLAGS="$TEMP_LDFLAGS"
fi

dnl check for gmtime_r(), fallback to gmtime_s() if that is unavailable
dnl fail if neither are available.
AC_MSG_CHECKING(for gmtime_r)
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <ctime>]],
[[ gmtime_r((const time_t *) nullptr, (struct tm *) nullptr); ]])],
[ AC_MSG_RESULT(yes); AC_DEFINE(HAVE_GMTIME_R, 1, [Define this symbol if gmtime_r is available]) ],
[ AC_MSG_RESULT(no);
AC_MSG_CHECKING(for gmtime_s);
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <ctime>]],
[[ gmtime_s((struct tm *) nullptr, (const time_t *) nullptr); ]])],
[ AC_MSG_RESULT(yes)],
[ AC_MSG_RESULT(no); AC_MSG_ERROR(Both gmtime_r and gmtime_s are unavailable) ]
)
]
)

# Check for different ways of gathering OS randomness
AC_MSG_CHECKING(for Linux getrandom syscall)
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <unistd.h>
Expand Down Expand Up @@ -1496,6 +1512,7 @@ AC_SUBST(LIBZCASH_LIBS)
AC_SUBST(QR_LIBS)
AC_SUBST(USE_NUM_GMP)
AC_SUBST(USE_NUM_OPENSSL)
AC_SUBST(HAVE_GMTIME_R)
AC_SUBST(HAVE_FDATASYNC)
AC_SUBST(HAVE_FULLFSYNC)
AC_SUBST(HAVE_O_CLOEXEC)
Expand Down
24 changes: 12 additions & 12 deletions src/utiltime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,10 @@ std::string DurationToDHMS(int64_t nDurationTime)
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 {};
}
Expand All @@ -112,10 +112,10 @@ std::string FormatISO8601DateTime(int64_t nTime) {
std::string FormatISO8601DateTimeForBackup(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 {};
}
Expand All @@ -125,10 +125,10 @@ std::string FormatISO8601DateTimeForBackup(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 {};
}
Expand All @@ -138,10 +138,10 @@ std::string FormatISO8601Date(int64_t nTime) {
std::string FormatISO8601Time(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 {};
}
Expand Down

0 comments on commit 0f750ca

Please sign in to comment.