mirror of
https://github.com/Retropex/bitcoin.git
synced 2025-05-28 13:02:38 +02:00
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:
parent
41fa2926d8
commit
a46484c8b3
17
configure.ac
17
configure.ac
@ -906,6 +906,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) ]
|
||||
)
|
||||
]
|
||||
)
|
||||
|
||||
dnl Check for different ways of gathering OS randomness
|
||||
AC_MSG_CHECKING(for Linux getrandom syscall)
|
||||
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <unistd.h>
|
||||
@ -1596,6 +1612,7 @@ AC_SUBST(EVENT_LIBS)
|
||||
AC_SUBST(EVENT_PTHREADS_LIBS)
|
||||
AC_SUBST(ZMQ_LIBS)
|
||||
AC_SUBST(QR_LIBS)
|
||||
AC_SUBST(HAVE_GMTIME_R)
|
||||
AC_SUBST(HAVE_FDATASYNC)
|
||||
AC_SUBST(HAVE_FULLFSYNC)
|
||||
AC_SUBST(HAVE_O_CLOEXEC)
|
||||
|
@ -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 {};
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user