From 079927ae1590a7d84d95a9cc69ff7e2064166d16 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Tue, 28 Dec 2021 11:38:26 -0800 Subject: [PATCH] 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. --- ChangeLog | 10 ++++++++++ lib/gettime.c | 2 ++ m4/gettime.m4 | 4 ++-- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5bbedae844..23c87e8e13 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2021-12-28 Paul Eggert + + 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 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]) ]) -- 2.39.5