Skip to content

Commit

Permalink
configure.ac, include/timehead.h: check also for mere declarations of…
Browse files Browse the repository at this point in the history
… localtime_r() etc.

Signed-off-by: Jim Klimov <[email protected]>
  • Loading branch information
jimklimov committed Aug 5, 2024
1 parent 66fc23f commit 2a0f7b2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
8 changes: 6 additions & 2 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -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"], [
Expand Down
12 changes: 6 additions & 6 deletions include/timehead.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 <string.h> /* memcpy */
Expand All @@ -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
Expand Down

0 comments on commit 2a0f7b2

Please sign in to comment.