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.
10 AC_DEFUN([gl_FUNC_GETTIMEOFDAY],
12 AC_REQUIRE([AC_C_RESTRICT])
13 AC_REQUIRE([gl_HEADER_SYS_TIME_H])
14 AC_CHECK_FUNCS_ONCE([gettimeofday])
16 AC_CACHE_CHECK([for gettimeofday with POSIX signature],
17 [gl_cv_func_gettimeofday_posix_signature],
20 [[#include <sys/time.h>
24 int (*f) (struct timeval *restrict, void *restrict) = gettimeofday;
26 return !(x | c.tv_sec | c.tv_usec);
28 [gl_cv_func_gettimeofday_posix_signature=yes],
29 [gl_cv_func_gettimeofday_posix_signature=no])])
31 gl_FUNC_GETTIMEOFDAY_CLOBBER
33 if test $gl_cv_func_gettimeofday_posix_signature != yes; then
34 REPLACE_GETTIMEOFDAY=1
36 if test $gl_cv_func_gettimeofday_clobber != yes; then
37 AC_LIBOBJ(gettimeofday)
38 gl_PREREQ_GETTIMEOFDAY
44 dnl See if gettimeofday clobbers the static buffer that localtime uses
45 dnl for its return value. The gettimeofday function from Mac OS X 10.0.4
46 dnl (i.e., Darwin 1.3.7) has this problem.
48 dnl If it does, then arrange to use gettimeofday and localtime only via
49 dnl the wrapper functions that work around the problem.
51 AC_DEFUN([gl_FUNC_GETTIMEOFDAY_CLOBBER],
53 AC_REQUIRE([gl_HEADER_SYS_TIME_H])
55 AC_CACHE_CHECK([whether gettimeofday clobbers localtime buffer],
56 [gl_cv_func_gettimeofday_clobber],
71 gettimeofday (&tv, NULL);
72 return memcmp (lt, &saved_lt, sizeof (struct tm)) != 0;
74 [gl_cv_func_gettimeofday_clobber=no],
75 [gl_cv_func_gettimeofday_clobber=yes],
76 dnl When crosscompiling, assume it is broken.
77 [gl_cv_func_gettimeofday_clobber=yes])])
79 if test $gl_cv_func_gettimeofday_clobber = yes; then
80 REPLACE_GETTIMEOFDAY=1
82 gl_GETTIMEOFDAY_REPLACE_LOCALTIME
83 AC_DEFINE([GETTIMEOFDAY_CLOBBERS_LOCALTIME], 1,
84 [Define if gettimeofday clobbers the localtime buffer.])
88 AC_DEFUN([gl_GETTIMEOFDAY_REPLACE_LOCALTIME], [
89 AC_LIBOBJ(gettimeofday)
90 gl_PREREQ_GETTIMEOFDAY
91 AC_DEFINE([gmtime], [rpl_gmtime],
92 [Define to rpl_gmtime if the replacement function should be used.])
93 AC_DEFINE([localtime], [rpl_localtime],
94 [Define to rpl_localtime if the replacement function should be used.])
97 # Prerequisites of lib/gettimeofday.c.
98 AC_DEFUN([gl_PREREQ_GETTIMEOFDAY], [
99 AC_CHECK_HEADERS([sys/timeb.h])
100 AC_CHECK_FUNCS([_ftime])