3 # Copyright (C) 2001, 2002, 2003, 2005 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_LIBSOURCES([gettimeofday.c, gettimeofday.h])
11 AC_REQUIRE([gl_C_RESTRICT])
12 AC_CHECK_FUNCS([gettimeofday])
14 AC_CHECK_TYPE([suseconds_t], ,
15 [AC_DEFINE([suseconds_t], [int],
16 [Define to `int' if `suseconds_t' is missing.])
19 # if TIME_WITH_SYS_TIME
20 # include <sys/time.h>
24 # include <sys/time.h>
31 AC_CACHE_CHECK([for struct timeval], fu_cv_sys_struct_timeval,
34 # if TIME_WITH_SYS_TIME
35 # include <sys/time.h>
39 # include <sys/time.h>
45 [static struct timeval x; x.tv_sec = x.tv_usec;],
46 fu_cv_sys_struct_timeval=yes,
47 fu_cv_sys_struct_timeval=no)
50 if test $fu_cv_sys_struct_timeval = yes; then
51 AC_DEFINE(HAVE_STRUCT_TIMEVAL, 1,
52 [Define if struct timeval is declared in <time.h> or <sys/time.h>. ])
55 AC_CACHE_CHECK([for gettimeofday whose signature conforms to POSIX],
56 [ac_cv_func_gettimeofday_posix_signature],
59 [[#include <sys/time.h>
65 int x = gettimeofday (&c, 0);
66 int (*f) (struct timeval *restrict, void *restrict) = gettimeofday;
67 return !(x | c.tv_sec | c.tv_usec);
69 [ac_cv_func_gettimeofday_posix_signature=yes],
70 [ac_cv_func_gettimeofday_posix_signature=no]))
71 if test $ac_cv_func_gettimeofday_posix_signature = yes; then
72 AC_DEFINE([HAVE_GETTIMEOFDAY_POSIX_SIGNATURE], 1,
73 [Define if gettimeofday's signature conforms to POSIX.])
74 AC_FUNC_GETTIMEOFDAY_CLOBBER
76 if test $ac_cv_func_gettimeofday_posix_signature != yes; then
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
137 AC_DEFINE(gettimeofday, rpl_gettimeofday,
138 [Define to rpl_gettimeofday if the replacement function should be used.])
142 AC_DEFUN([gl_GETTIMEOFDAY_REPLACE_LOCALTIME], [
143 gl_PREREQ_GETTIMEOFDAY
144 AC_DEFINE(GETTIMEOFDAY_CLOBBERS_LOCALTIME, 1,
145 [Define if gettimeofday clobbers the localtime buffer.])
146 AC_LIBOBJ(gettimeofday)
147 AC_DEFINE(gmtime, rpl_gmtime,
148 [Define to rpl_gmtime if the replacement function should be used.])
149 AC_DEFINE(localtime, rpl_localtime,
150 [Define to rpl_localtime if the replacement function should be used.])
153 # Prerequisites of lib/gettimeofday.c.
154 AC_DEFUN([gl_PREREQ_GETTIMEOFDAY], [
155 AC_REQUIRE([AC_HEADER_TIME])
156 AC_CHECK_HEADERS([sys/timeb.h])
157 AC_CHECK_FUNCS([_ftime])