1# $Id: clock.m4,v 1.2 2007/11/27 01:27:42 bostic Exp $
2
3# Configure clocks and timers.
4AC_DEFUN(AC_TIMERS, [
5
6AC_CHECK_FUNCS(gettimeofday localtime time strftime)
7
8# AIX 4.3 will link applications with calls to clock_gettime, but the
9# calls always fail.
10case "$host_os" in
11aix4.3.*)
12	;;
13*)
14	AC_CHECK_FUNCS(clock_gettime);;
15esac
16
17# clock_gettime -- monotonic clocks.
18#	Check to see if we can get a monotonic clock.  We actually try and
19#	run the program if possible, because we don't trust the #define's
20#	existence to mean the clock really exists.
21AC_CACHE_CHECK([for clock_gettime monotonic clock], db_cv_clock_monotonic, [
22AC_TRY_RUN([
23#include <sys/time.h>
24main() {
25	struct timespec t;
26	return (clock_gettime(CLOCK_MONOTONIC, &t) != 0);
27}], db_cv_clock_monotonic=yes, db_cv_clock_monotonic=no,
28AC_TRY_LINK([
29#include <sys/time.h>], [
30struct timespec t;
31clock_gettime(CLOCK_MONOTONIC, &t);
32], db_cv_clock_monotonic=yes, db_cv_clock_monotonic=no))
33])
34if test "$db_cv_clock_monotonic" = "yes"; then
35	AC_DEFINE(HAVE_CLOCK_MONOTONIC)
36	AH_TEMPLATE(HAVE_CLOCK_MONOTONIC,
37	    [Define to 1 if clock_gettime supports CLOCK_MONOTONIC.])
38fi
39
40# ctime_r --
41#
42# There are two versions of ctime_r, one of which takes a buffer length as a
43# third argument, and one which only takes two arguments.  (There is also a
44# difference in return values and the type of the 3rd argument, but we handle
45# those problems in the code itself.)
46AC_CHECK_FUNCS(ctime_r)
47if test "$ac_cv_func_ctime_r" = "yes"; then
48AC_CACHE_CHECK([for 2 or 3 argument version of ctime_r], db_cv_ctime_r_3arg, [
49AC_TRY_LINK([
50#include <time.h>], [
51	ctime_r(NULL, NULL, 100);
52],  [db_cv_ctime_r_3arg="3-argument"], [db_cv_ctime_r_3arg="2-argument"])])
53fi
54if test "$db_cv_ctime_r_3arg" = "3-argument"; then
55	AC_DEFINE(HAVE_CTIME_R_3ARG)
56	AH_TEMPLATE(HAVE_CTIME_R_3ARG,
57	    [Define to 1 if ctime_r takes a buffer length as a third argument.])
58fi
59])
60