From 2a0f7b2284701990be02a9e8275db3f12397b531 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Mon, 5 Aug 2024 14:37:12 +0200 Subject: [PATCH] configure.ac, include/timehead.h: check also for mere declarations of localtime_r() etc. Signed-off-by: Jim Klimov --- configure.ac | 8 ++++++-- include/timehead.h | 12 ++++++------ 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/configure.ac b/configure.ac index 45df72dc52..13cf303e59 100644 --- a/configure.ac +++ b/configure.ac @@ -938,8 +938,12 @@ AC_CHECK_FUNCS(strtof strtok_r fileno sigemptyset sigaction, dnl For these we have a fallback implementation via the other, dnl if at least one is available, so initial check is quiet. dnl This typically pops up in POSIX vs. Windows builds: -AC_CHECK_FUNCS(localtime_r localtime_s gmtime_r gmtime_s timegm _mkgmtime, - [], []) +dnl Reminder: the former checks for declarations in headers, +dnl the latter checks if known libraries suffice for linker. +dnl Might need AC_CHECK_LIBS as well to populate the list with +dnl known variants? +AC_CHECK_DECLS([localtime_r, localtime_s, gmtime_r, gmtime_s, timegm, _mkgmtime], [], [], [$CODE_TIMEINCL]) +AC_CHECK_FUNCS(localtime_r localtime_s gmtime_r gmtime_s timegm _mkgmtime, [], []) AC_MSG_CHECKING([for at least one gmtime implementation]) AS_IF([test x"${ac_cv_func_gmtime_s}-${ac_cv_func_gmtime_r}" = "xno-no" && test x"${ac_cv_have_decl_gmtime_s}-${ac_cv_have_decl_gmtime_r}" = "xno-no"], [ diff --git a/include/timehead.h b/include/timehead.h index de72d9b8fe..984f8ff56b 100644 --- a/include/timehead.h +++ b/include/timehead.h @@ -44,8 +44,8 @@ extern "C" { char * strptime(const char *buf, const char *fmt, struct tm *tm); #endif -#ifndef HAVE_LOCALTIME_R -# ifdef HAVE_LOCALTIME_S +#if !(defined HAVE_LOCALTIME_R && HAVE_LOCALTIME_R) && !(defined HAVE_DECL_LOCALTIME_R && HAVE_DECL_LOCALTIME_R) +# if (defined HAVE_LOCALTIME_S && HAVE_LOCALTIME_S) || (defined HAVE_DECL_LOCALTIME_S && HAVE_DECL_LOCALTIME_S) /* A bit of a silly trick, but should help on MSYS2 builds it seems */ # define localtime_r(timer, buf) localtime_s(timer, buf) # else @@ -59,8 +59,8 @@ static inline struct tm *localtime_r( const time_t *timer, struct tm *buf ) { # endif #endif -#ifndef HAVE_GMTIME_R -# ifdef HAVE_GMTIME_S +#if !(defined HAVE_GMTIME_R && HAVE_GMTIME_R) && !(defined HAVE_DECL_GMTIME_R && HAVE_DECL_GMTIME_R) +# if (defined HAVE_GMTIME_S && HAVE_GMTIME_S) || (defined HAVE_DECL_GMTIME_S && HAVE_DECL_GMTIME_S) # define gmtime_r(timer, buf) gmtime_s(timer, buf) # else # include /* memcpy */ @@ -73,8 +73,8 @@ static inline struct tm *gmtime_r( const time_t *timer, struct tm *buf ) { # endif #endif -#ifndef HAVE_TIMEGM -# ifdef HAVE__MKGMTIME +#if !(defined HAVE_TIMEGM && HAVE_TIMEGM) && !(defined HAVE_DECL_TIMEGM && HAVE_DECL_TIMEGM) +# if (defined HAVE__MKGMTIME && HAVE__MKGMTIME) || (defined HAVE_DECL__MKGMTIME && HAVE_DECL__MKGMTIME) # define timegm(tm) _mkgmtime(tm) # else # ifdef WANT_TIMEGM_FALLBACK