]> Savannah Git Hosting - gnulib.git/commitdiff
time_r: Fix for mingw (regression from 2019-11-16).
authorBruno Haible <bruno@clisp.org>
Sun, 24 Nov 2019 13:32:23 +0000 (14:32 +0100)
committerBruno Haible <bruno@clisp.org>
Sun, 24 Nov 2019 14:02:39 +0000 (15:02 +0100)
* m4/time_r.m4 (gl_TIME_R): Revert to using AC_CHECK_FUNCS_ONCE. Use the
AC_LINK_IFELSE test only if the function does not appear to exist.

ChangeLog
m4/time_r.m4

index 984792b25b0734328a5740605eb084159b007567..5c2f5c5869fc62d9217cd99afbe289ae3608f6ee 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2019-11-24  Bruno Haible  <bruno@clisp.org>
+
+       time_r: Fix for mingw (regression from 2019-11-16).
+       * m4/time_r.m4 (gl_TIME_R): Revert to using AC_CHECK_FUNCS_ONCE. Use the
+       AC_LINK_IFELSE test only if the function does not appear to exist.
+
 2019-11-24  Bruno Haible  <bruno@clisp.org>
 
        wcstok: Add tests.
index 72cc97508a112c5fe7c9579cd772d5533c9ce75c..cc4b3e009b97afeef829f61d16ae501aecbf7ee5 100644 (file)
@@ -30,28 +30,8 @@ AC_DEFUN([gl_TIME_R],
     HAVE_DECL_LOCALTIME_R=0
   fi
 
-  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 <time.h> provides the functions asctime_r, ctime_r,
-               gmtime_r, localtime_r only if <unistd.h> or <pthread.h> has
-               been included before.  */
-            #if defined __MINGW32__
-            # include <unistd.h>
-            #endif
-            #include <time.h>
-          ]],
-          [[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
+  AC_CHECK_FUNCS_ONCE([localtime_r])
+  if test $ac_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],
@@ -84,6 +64,32 @@ AC_DEFUN([gl_TIME_R],
     fi
   else
     HAVE_LOCALTIME_R=0
+    dnl On mingw, localtime_r() is defined as an inline function; use through a
+    dnl direct function call works but the use as a function pointer leads to a
+    dnl link error.
+    AC_CACHE_CHECK([whether localtime_r exists as an inline function],
+      [gl_cv_func_localtime_r_inline],
+      [AC_LINK_IFELSE(
+         [AC_LANG_PROGRAM(
+            [[/* mingw's <time.h> provides the functions asctime_r, ctime_r,
+                 gmtime_r, localtime_r only if <unistd.h> or <pthread.h> has
+                 been included before.  */
+              #if defined __MINGW32__
+              # include <unistd.h>
+              #endif
+              #include <time.h>
+            ]],
+            [[time_t a;
+              struct tm r;
+              localtime_r (&a, &r);
+            ]])
+         ],
+         [gl_cv_func_localtime_r_inline=yes],
+         [gl_cv_func_localtime_r_inline=no])
+      ])
+    if test $gl_cv_func_localtime_r_inline = yes; then
+      REPLACE_LOCALTIME_R=1
+    fi
   fi
 ])