diff options
-rw-r--r-- | ChangeLog | 10 | ||||
-rw-r--r-- | lib/gettime.c | 2 | ||||
-rw-r--r-- | m4/gettime.m4 | 4 |
3 files changed, 14 insertions, 2 deletions
@@ -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 8f28a32df1..87f9347e08 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 de7c33046c..cb58bc8ebd 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]) ]) |