From b7bf9f4361c8d78ccfda7a30ff31f7a406ea972e Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sat, 16 Nov 2019 13:13:58 +0100 Subject: [PATCH] time_r: Fix for mingw. Reported by Christian Biesinger in . * lib/time.in.h: On mingw, include . * m4/time_r.m4 (gl_TIME_R): On mingw, include before . Test for localtime_r in a way that works when it is defined as an inline function. --- ChangeLog | 10 ++++++++++ lib/time.in.h | 6 ++++++ m4/time_r.m4 | 43 +++++++++++++++++++++++++++++++++++++++---- 3 files changed, 55 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 7cc8bdde64..c011710071 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2019-11-16 Bruno Haible + + time_r: Fix for mingw. + Reported by Christian Biesinger in + . + * lib/time.in.h: On mingw, include . + * m4/time_r.m4 (gl_TIME_R): On mingw, include before + . Test for localtime_r in a way that works when it is defined + as an inline function. + 2019-11-13 Bruno Haible havelib: Revert last change. diff --git a/lib/time.in.h b/lib/time.in.h index 94e1da3a84..dc0050347b 100644 --- a/lib/time.in.h +++ b/lib/time.in.h @@ -37,6 +37,12 @@ # define _@GUARD_PREFIX@_TIME_H +/* mingw's provides the functions asctime_r, ctime_r, gmtime_r, + localtime_r only if or has been included before. */ +# if defined __MINGW32__ +# include +# endif + # @INCLUDE_NEXT@ @NEXT_TIME_H@ /* NetBSD 5.0 mis-defines NULL. */ diff --git a/m4/time_r.m4 b/m4/time_r.m4 index 5caeca7509..72cc97508a 100644 --- a/m4/time_r.m4 +++ b/m4/time_r.m4 @@ -17,19 +17,54 @@ AC_DEFUN([gl_TIME_R], dnl Some systems don't declare localtime_r() and gmtime_r() if _REENTRANT is dnl not defined. - AC_CHECK_DECLS([localtime_r], [], [], [[#include ]]) + AC_CHECK_DECLS([localtime_r], [], [], + [[/* mingw's provides the functions asctime_r, ctime_r, + gmtime_r, localtime_r only if or has + been included before. */ + #if defined __MINGW32__ + # include + #endif + #include + ]]) if test $ac_cv_have_decl_localtime_r = no; then HAVE_DECL_LOCALTIME_R=0 fi - AC_CHECK_FUNCS_ONCE([localtime_r]) - if test $ac_cv_func_localtime_r = yes; then + dnl We can't use AC_CHECK_FUNC here, because localtime_r() is defined as an + dnl inline function on mingw. + AC_CACHE_CHECK([for localtime_r], [gl_cv_func_localtime_r], + [AC_LINK_IFELSE( + [AC_LANG_PROGRAM( + [[/* mingw's provides the functions asctime_r, ctime_r, + gmtime_r, localtime_r only if or has + been included before. */ + #if defined __MINGW32__ + # include + #endif + #include + ]], + [[time_t a; + struct tm r; + localtime_r (&a, &r); + ]]) + ], + [gl_cv_func_localtime_r=yes], + [gl_cv_func_localtime_r=no]) + ]) + if test $gl_cv_func_localtime_r = yes; then HAVE_LOCALTIME_R=1 AC_CACHE_CHECK([whether localtime_r is compatible with its POSIX signature], [gl_cv_time_r_posix], [AC_COMPILE_IFELSE( [AC_LANG_PROGRAM( - [[#include ]], + [[/* mingw's provides the functions asctime_r, ctime_r, + gmtime_r, localtime_r only if or has + been included before. */ + #if defined __MINGW32__ + # include + #endif + #include + ]], [[/* We don't need to append 'restrict's to the argument types, even though the POSIX signature has the 'restrict's, since C99 says they can't affect type compatibility. */ -- 2.39.5