bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 1/5] gettime: port better to non-POSIX C2x


From: Paul Eggert
Subject: [PATCH 1/5] gettime: port better to non-POSIX C2x
Date: Tue, 28 Dec 2021 12:05:10 -0800

C2x requires a function timespec_get; prefer that to
gettimeofday, since it has better resolution.
* lib/gettime.c (gettime): Prefer timespec_get to gettimeofday.
* m4/gettime.m4 (gl_GETTIME): Check for timespec_get.
Omit a check for gettimeofday; not needed because
the gettime module depends on the gettimeofday module.
---
 ChangeLog     | 10 ++++++++++
 lib/gettime.c |  2 ++
 m4/gettime.m4 |  4 ++--
 3 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 5bbedae84..23c87e8e1 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2021-12-28  Paul Eggert  <eggert@cs.ucla.edu>
+
+       gettime: port better to non-POSIX C2x
+       C2x requires a function timespec_get; prefer that to
+       gettimeofday, since it has better resolution.
+       * lib/gettime.c (gettime): Prefer timespec_get to gettimeofday.
+       * m4/gettime.m4 (gl_GETTIME): Check for timespec_get.
+       Omit a check for gettimeofday; not needed because
+       the gettime module depends on the gettimeofday module.
+
 2021-12-28  Bruno Haible  <bruno@clisp.org>
 
        gen-uni-tables: Produce license notices suitable for Gnulib.
diff --git a/lib/gettime.c b/lib/gettime.c
index 8f28a32df..87f9347e0 100644
--- a/lib/gettime.c
+++ b/lib/gettime.c
@@ -30,6 +30,8 @@ gettime (struct timespec *ts)
 {
 #if defined CLOCK_REALTIME && HAVE_CLOCK_GETTIME
   clock_gettime (CLOCK_REALTIME, ts);
+#elif defined HAVE_TIMESPEC_GET
+  timespec_get (ts, TIME_UTC);
 #else
   struct timeval tv;
   gettimeofday (&tv, NULL);
diff --git a/m4/gettime.m4 b/m4/gettime.m4
index de7c33046..cb58bc8eb 100644
--- a/m4/gettime.m4
+++ b/m4/gettime.m4
@@ -1,4 +1,4 @@
-# gettime.m4 serial 9
+# gettime.m4 serial 10
 dnl Copyright (C) 2002, 2004-2006, 2009-2021 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,5 +9,5 @@ AC_DEFUN([gl_GETTIME],
   dnl Prerequisites of lib/gettime.c.
   AC_REQUIRE([gl_CLOCK_TIME])
   AC_REQUIRE([gl_TIMESPEC])
-  AC_CHECK_FUNCS_ONCE([gettimeofday])
+  AC_CHECK_FUNCS_ONCE([timespec_get])
 ])
-- 
2.33.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]