]> Savannah Git Hosting - gnulib.git/commitdiff
timespec_get: Fix compilation error with MSVC 14.
authorBruno Haible <bruno@clisp.org>
Sun, 4 Sep 2022 15:09:53 +0000 (17:09 +0200)
committerBruno Haible <bruno@clisp.org>
Mon, 5 Sep 2022 02:00:06 +0000 (04:00 +0200)
* m4/gettime.m4 (gl_CHECK_FUNC_TIMESPEC_GET): New macro.
(gl_GETTIME): Use it instead of AC_CHECK_FUNCS_ONCE.
* m4/timespec_get.m4 (gl_FUNC_TIMESPEC_GET): Likewise.

ChangeLog
m4/gettime.m4
m4/timespec_get.m4

index bfefa6f2bd1ae6c89fdebe0bf4114d3269db4171..5d39fbb0b41c00e88bb6267d85223acc313266a8 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2022-09-04  Bruno Haible  <bruno@clisp.org>
+
+       timespec_get: Fix compilation error with MSVC 14.
+       * m4/gettime.m4 (gl_CHECK_FUNC_TIMESPEC_GET): New macro.
+       (gl_GETTIME): Use it instead of AC_CHECK_FUNCS_ONCE.
+       * m4/timespec_get.m4 (gl_FUNC_TIMESPEC_GET): Likewise.
+
 2022-09-04  Bruno Haible  <bruno@clisp.org>
 
        stdbool: Fix compilation error in C++ mode with MSVC 14.
index f0aeb4d0e4dd1af5aa42418de6b4bf421dce750d..c3e0713b5759d278d1485678fae9dbac66297c88 100644 (file)
@@ -1,4 +1,4 @@
-# gettime.m4 serial 11
+# gettime.m4 serial 12
 dnl Copyright (C) 2002, 2004-2006, 2009-2022 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -9,7 +9,34 @@ AC_DEFUN([gl_GETTIME],
   dnl Prerequisites of lib/gettime.c.
   AC_REQUIRE([gl_CLOCK_TIME])
   AC_REQUIRE([gl_TIMESPEC])
-  AC_CHECK_FUNCS_ONCE([timespec_get])
+
+  AC_REQUIRE([gl_CHECK_FUNC_TIMESPEC_GET])
+  if test $gl_cv_func_timespec_get = yes; then
+    AC_DEFINE([HAVE_TIMESPEC_GET], [1],
+      [Define if you have the timespec_get function.])
+  fi
+])
+
+dnl Tests whether the function timespec_get exists.
+dnl Sets gl_cv_func_timespec_get.
+AC_DEFUN([gl_CHECK_FUNC_TIMESPEC_GET],
+[
+  dnl Persuade OpenBSD <time.h> to declare timespec_get().
+  AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
+
+  dnl We can't use AC_CHECK_FUNC here, because timespec_get() is defined as a
+  dnl static inline function in <time.h> on MSVC 14.
+  AC_CACHE_CHECK([for timespec_get], [gl_cv_func_timespec_get],
+    [AC_LINK_IFELSE(
+       [AC_LANG_PROGRAM(
+          [[#include <time.h>
+            struct timespec ts;
+          ]],
+          [[return timespec_get (&ts, 0);]])
+       ],
+       [gl_cv_func_timespec_get=yes],
+       [gl_cv_func_timespec_get=no])
+    ])
 ])
 
 AC_DEFUN([gl_GETTIME_RES],
index cc5ce299dee2c5d7228bcb0752f0beb8a6de98b8..acea56d6268ac3d1f8add5e5e4512096213225cb 100644 (file)
@@ -1,4 +1,4 @@
-# timespec_get.m4 serial 2
+# timespec_get.m4 serial 3
 dnl Copyright (C) 2021-2022 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -11,8 +11,8 @@ AC_DEFUN([gl_FUNC_TIMESPEC_GET],
   dnl Persuade OpenBSD <time.h> to declare timespec_get().
   AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
 
-  AC_CHECK_FUNCS_ONCE([timespec_get])
-  if test $ac_cv_func_timespec_get != yes; then
+  AC_REQUIRE([gl_CHECK_FUNC_TIMESPEC_GET])
+  if test $gl_cv_func_timespec_get != yes; then
     HAVE_TIMESPEC_GET=0
   fi
 ])