3 # Copyright (C) 2001, 2002, 2003, 2005, 2007 Free Software Foundation, Inc.
4 # This file is free software; the Free Software Foundation
5 # gives unlimited permission to copy and/or distribute it,
6 # with or without modifications, as long as this notice is preserved.
8 AC_DEFUN([gl_FUNC_GETTIMEOFDAY],
10 AC_REQUIRE([AC_C_RESTRICT])
11 AC_REQUIRE([AC_HEADER_TIME])
12 AC_CHECK_HEADERS_ONCE([sys/time.h])
13 AC_CHECK_FUNCS([gettimeofday])
15 AC_CHECK_TYPE([suseconds_t], ,
16 [AC_DEFINE([suseconds_t], [int],
17 [Define to `int' if `suseconds_t' is missing.])
20 # if TIME_WITH_SYS_TIME
21 # include <sys/time.h>
25 # include <sys/time.h>
32 AC_CACHE_CHECK([for struct timeval], [fu_cv_sys_struct_timeval],
35 # if TIME_WITH_SYS_TIME
36 # include <sys/time.h>
40 # include <sys/time.h>
46 [static struct timeval x; x.tv_sec = x.tv_usec;],
47 fu_cv_sys_struct_timeval=yes,
48 fu_cv_sys_struct_timeval=no)
51 if test $fu_cv_sys_struct_timeval = yes; then
52 AC_DEFINE(HAVE_STRUCT_TIMEVAL, 1,
53 [Define if struct timeval is declared in <time.h> or <sys/time.h>. ])
56 AC_CACHE_CHECK([for gettimeofday whose signature conforms to POSIX],
57 [ac_cv_func_gettimeofday_posix_signature],
60 [[#include <sys/time.h>
66 int x = gettimeofday (&c, 0);
67 int (*f) (struct timeval *restrict, void *restrict) = gettimeofday;
68 return !(x | c.tv_sec | c.tv_usec);
70 [ac_cv_func_gettimeofday_posix_signature=yes],
71 [ac_cv_func_gettimeofday_posix_signature=no])])
72 if test $ac_cv_func_gettimeofday_posix_signature = yes; then
73 AC_DEFINE([HAVE_GETTIMEOFDAY_POSIX_SIGNATURE], 1,
74 [Define if gettimeofday's signature conforms to POSIX.])
75 AC_FUNC_GETTIMEOFDAY_CLOBBER
77 gl_PREREQ_GETTIMEOFDAY
78 AC_LIBOBJ([gettimeofday])
82 dnl From Jim Meyering.
84 dnl See if gettimeofday clobbers the static buffer that localtime uses
85 dnl for its return value. The gettimeofday function from Mac OS X 10.0.4
86 dnl (i.e., Darwin 1.3.7) has this problem.
88 dnl If it does, then arrange to use gettimeofday and localtime only via
89 dnl the wrapper functions that work around the problem.
91 AC_DEFUN([AC_FUNC_GETTIMEOFDAY_CLOBBER],
93 AC_REQUIRE([AC_HEADER_TIME])
94 AC_CACHE_CHECK([whether gettimeofday clobbers localtime buffer],
95 [jm_cv_func_gettimeofday_clobber],
100 #if TIME_WITH_SYS_TIME
101 # include <sys/time.h>
105 # include <sys/time.h>
122 gettimeofday (&tv, NULL);
123 if (memcmp (lt, &saved_lt, sizeof (struct tm)) != 0)
129 jm_cv_func_gettimeofday_clobber=no,
130 jm_cv_func_gettimeofday_clobber=yes,
131 dnl When crosscompiling, assume it is broken.
132 jm_cv_func_gettimeofday_clobber=yes)
134 if test $jm_cv_func_gettimeofday_clobber = yes; then
135 gl_GETTIMEOFDAY_REPLACE_LOCALTIME
139 AC_DEFUN([gl_GETTIMEOFDAY_REPLACE_LOCALTIME], [
140 AC_LIBOBJ(gettimeofday)
141 gl_PREREQ_GETTIMEOFDAY
142 AC_DEFINE([GETTIMEOFDAY_CLOBBERS_LOCALTIME], 1,
143 [Define if gettimeofday clobbers the localtime buffer.])
144 AC_DEFINE([gmtime], [rpl_gmtime],
145 [Define to rpl_gmtime if the replacement function should be used.])
146 AC_DEFINE([localtime], [rpl_localtime],
147 [Define to rpl_localtime if the replacement function should be used.])
148 AC_DEFINE([tzset], [rpl_tzset],
149 [Define to rpl_tzset if the replacement function should be used.])
152 # Prerequisites of lib/gettimeofday.c.
153 AC_DEFUN([gl_PREREQ_GETTIMEOFDAY], [
154 AC_REQUIRE([AC_HEADER_TIME])
155 AC_CHECK_HEADERS([sys/timeb.h])
156 AC_CHECK_FUNCS([_ftime])