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 GETTIMEOFDAY_REPLACEMENT=1
35 if test $gl_cv_func_gettimeofday_clobber != yes; then
36 AC_LIBOBJ(gettimeofday)
37 gl_PREREQ_GETTIMEOFDAY
43 dnl See if gettimeofday clobbers the static buffer that localtime uses
44 dnl for its return value. The gettimeofday function from Mac OS X 10.0.4
45 dnl (i.e., Darwin 1.3.7) has this problem.
47 dnl If it does, then arrange to use gettimeofday and localtime only via
48 dnl the wrapper functions that work around the problem.
50 AC_DEFUN([gl_FUNC_GETTIMEOFDAY_CLOBBER],
52 AC_REQUIRE([gl_HEADER_SYS_TIME_H])
54 AC_CACHE_CHECK([whether gettimeofday clobbers localtime buffer],
55 [gl_cv_func_gettimeofday_clobber],
70 gettimeofday (&tv, NULL);
71 return memcmp (lt, &saved_lt, sizeof (struct tm)) != 0;
73 [gl_cv_func_gettimeofday_clobber=no],
74 [gl_cv_func_gettimeofday_clobber=yes],
75 dnl When crosscompiling, assume it is broken.
76 [gl_cv_func_gettimeofday_clobber=yes])])
78 if test $gl_cv_func_gettimeofday_clobber = yes; then
79 GETTIMEOFDAY_REPLACEMENT=1
80 gl_GETTIMEOFDAY_REPLACE_LOCALTIME
81 AC_DEFINE([GETTIMEOFDAY_CLOBBERS_LOCALTIME], 1,
82 [Define if gettimeofday clobbers the localtime buffer.])
86 AC_DEFUN([gl_GETTIMEOFDAY_REPLACE_LOCALTIME], [
87 AC_LIBOBJ(gettimeofday)
88 gl_PREREQ_GETTIMEOFDAY
89 AC_DEFINE([gmtime], [rpl_gmtime],
90 [Define to rpl_gmtime if the replacement function should be used.])
91 AC_DEFINE([localtime], [rpl_localtime],
92 [Define to rpl_localtime if the replacement function should be used.])
95 # Prerequisites of lib/gettimeofday.c.
96 AC_DEFUN([gl_PREREQ_GETTIMEOFDAY], [
97 AC_CHECK_HEADERS([sys/timeb.h])
98 AC_CHECK_FUNCS([_ftime])