dnl CF_FUNC_GETTIME version: 3 updated: 2024/05/11 13:40:02
dnl ---------------
dnl Check for gettimeofday or clock_gettime.  In 2023, the former is still more
dnl widely supported, but "deprecated" (2008), so we will use the latter if it
dnl is available, to reduce compiler warnings.
AC_DEFUN([CF_FUNC_GETTIME],[
cf_save_libs="$LIBS"
AC_CHECK_FUNC(clock_gettime,
	cf_cv_test_clock_gettime=yes,
	AC_CHECK_LIB(rt, clock_gettime,
		[LIBS="-lrt $LIBS"
		 cf_cv_test_clock_gettime=yes],
		 cf_cv_test_clock_gettime=no))

if test "$cf_cv_test_clock_gettime" = yes ; then
AC_CACHE_CHECK(if clock_gettime links,cf_cv_func_clock_gettime,[
		AC_TRY_LINK([
$ac_includes_default
#include <time.h>
		],
		[struct timespec ts;
		int rc = clock_gettime(CLOCK_REALTIME, &ts)
			   + clock_gettime(CLOCK_MONOTONIC, &ts);
		 (void) rc; (void)ts],
		[cf_cv_func_clock_gettime=yes],
		[cf_cv_func_clock_gettime=no])
])
else
	cf_cv_func_clock_gettime=no
fi

if test "$cf_cv_func_clock_gettime" = yes
then
	AC_DEFINE(HAVE_CLOCK_GETTIME,1,[Define to 1 if we have clock_gettime function])
else
AC_CHECK_FUNC(gettimeofday,
	AC_DEFINE(HAVE_GETTIMEOFDAY,1,[Define to 1 if we have gettimeofday function]),[

AC_CHECK_LIB(bsd, gettimeofday,
	AC_DEFINE(HAVE_GETTIMEOFDAY,1,[Define to 1 if we have gettimeofday function])
	CF_ADD_LIB(bsd))])dnl CLIX: bzero, select, gettimeofday
fi
])dnl
