+2026-06-20 Paul Eggert <eggert@cs.ucla.edu>
+
+ gethrxtime: don’t use nanouptime, microuptime
+ * lib/gethrxtime.c (gethrxtime): On platforms with
+ CLOCK_MONOTONIC, try it first. If it fails, just fall back on
+ CLOCK_REALTIME as that’s what current_timespec would do anyway.
+ On platforms lacking CLOCK_MONOTONIC, just use current_timespec.
+ * m4/gethrxtime.m4 (gl_GETHRXTIME): Don’t check for microuptime or
+ nanouptime. They aren’t exposed to user space by BSD kernels now,
+ and it’s not clear that they ever were.
+
2026-06-19 Paul Eggert <eggert@cs.ucla.edu>
fstatat: don’t mess with CFLAGS
xtime_t
gethrxtime (void)
{
-# if HAVE_NANOUPTIME
- {
- struct timespec ts;
- nanouptime (&ts);
- return xtime_make (ts.tv_sec, ts.tv_nsec);
- }
+ struct timespec ts;
+# if defined CLOCK_MONOTONIC && HAVE_CLOCK_GETTIME
+ /* If available, use a monotonically increasing clock.
+ Otherwise fall back on CLOCK_REALTIME as that is
+ what current_timespec would do anyway. */
+ if (clock_gettime (CLOCK_MONOTONIC, &ts) < 0)
+ clock_gettime (CLOCK_REALTIME, &ts);
# else
-
-# if defined CLOCK_MONOTONIC && HAVE_CLOCK_GETTIME
- {
- struct timespec ts;
- if (clock_gettime (CLOCK_MONOTONIC, &ts) == 0)
- return xtime_make (ts.tv_sec, ts.tv_nsec);
- }
-# endif
-
-# if HAVE_MICROUPTIME
- {
- struct timeval tv;
- microuptime (&tv);
- return xtime_make (tv.tv_sec, 1000 * tv.tv_usec);
- }
-
-# else
- /* No monotonically increasing clocks are available; fall back on a
- clock that might jump backwards, since it's the best we can do. */
- {
- struct timespec ts;
- gettime (&ts);
- return xtime_make (ts.tv_sec, ts.tv_nsec);
- }
-# endif
+ ts = current_timespec ();
# endif
+ return xtime_make (ts.tv_sec, ts.tv_nsec);
}
#endif
dnl Find libraries needed to link lib/gethrxtime.c.
AC_REQUIRE([gl_CLOCK_TIME])
AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
- AC_CHECK_FUNCS_ONCE([microuptime nanouptime])
- if test $ac_cv_func_nanouptime != yes \
- && { test $ac_cv_have_decl_gethrtime = no \
- || test $gl_cv_arithmetic_hrtime_t = no; }; then
+ if { test $ac_cv_have_decl_gethrtime = no \
+ || test $gl_cv_arithmetic_hrtime_t = no; }; then
AC_CACHE_CHECK([whether CLOCK_MONOTONIC or CLOCK_REALTIME is defined],
[gl_cv_have_clock_gettime_macro],
[AC_EGREP_CPP([have_clock_gettime_macro],