]> Savannah Git Hosting - gnulib.git/commitdiff
gettime: port better to non-POSIX C2x
authorPaul Eggert <eggert@cs.ucla.edu>
Tue, 28 Dec 2021 19:38:26 +0000 (11:38 -0800)
committerPaul Eggert <eggert@cs.ucla.edu>
Tue, 28 Dec 2021 20:04:48 +0000 (12:04 -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
lib/gettime.c
m4/gettime.m4

index 5bbedae8441424490cce2c878c173dd85e677c92..23c87e8e1372df00df8476c66d5bb52259dc0852 100644 (file)
--- 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.
index 8f28a32df16ab8c222669164623b40854557099d..87f9347e08029f7b526a7dcedaa1e6e0c4b03897 100644 (file)
@@ -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);
index de7c33046c2645a5bd6fa26d99c15cd738109c8b..cb58bc8ebd49ab6eba7e12616af92604104f0bec 100644 (file)
@@ -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])
 ])