3 # Copyright (C) 2001-2003, 2005, 2007, 2009-2010 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_REQUIRE([gl_HEADER_SYS_TIME_H_DEFAULTS])
15 AC_CHECK_FUNCS_ONCE([gettimeofday])
17 gl_gettimeofday_timezone=void
18 if test $ac_cv_func_gettimeofday = yes; then
19 gl_FUNC_GETTIMEOFDAY_CLOBBER
20 AC_CACHE_CHECK([for gettimeofday with POSIX signature],
21 [gl_cv_func_gettimeofday_posix_signature],
24 [[#include <sys/time.h>
26 int gettimeofday (struct timeval *restrict, void *restrict);
28 [[/* glibc uses struct timezone * rather than the POSIX void *
29 if _GNU_SOURCE is defined. However, since the only portable
30 use of gettimeofday uses NULL as the second parameter, and
31 since the glibc definition is actually more typesafe, it is
32 not worth wrapping this to get a compliant signature. */
33 int (*f) (struct timeval *restrict, void *restrict)
36 return !(x | c.tv_sec | c.tv_usec);
38 [gl_cv_func_gettimeofday_posix_signature=yes],
41 [[#include <sys/time.h>
42 int gettimeofday (struct timeval *restrict, struct timezone *restrict);
44 [gl_cv_func_gettimeofday_posix_signature=almost],
45 [gl_cv_func_gettimeofday_posix_signature=no])])])
46 if test $gl_cv_func_gettimeofday_posix_signature = almost; then
47 gl_gettimeofday_timezone='struct timezone'
48 elif test $gl_cv_func_gettimeofday_posix_signature != yes; then
49 REPLACE_GETTIMEOFDAY=1
50 AC_LIBOBJ([gettimeofday])
51 gl_PREREQ_GETTIMEOFDAY
54 AC_DEFINE_UNQUOTED([GETTIMEOFDAY_TIMEZONE], [$gl_gettimeofday_timezone],
55 [Define this to 'void' or 'struct timezone' to match the system's
56 declaration of the second argument to gettimeofday.])
60 dnl See if gettimeofday clobbers the static buffer that localtime uses
61 dnl for its return value. The gettimeofday function from Mac OS X 10.0.4
62 dnl (i.e., Darwin 1.3.7) has this problem.
64 dnl If it does, then arrange to use gettimeofday and localtime only via
65 dnl the wrapper functions that work around the problem.
67 AC_DEFUN([gl_FUNC_GETTIMEOFDAY_CLOBBER],
69 AC_REQUIRE([gl_HEADER_SYS_TIME_H])
71 AC_CACHE_CHECK([whether gettimeofday clobbers localtime buffer],
72 [gl_cv_func_gettimeofday_clobber],
87 gettimeofday (&tv, NULL);
88 return memcmp (lt, &saved_lt, sizeof (struct tm)) != 0;
90 [gl_cv_func_gettimeofday_clobber=no],
91 [gl_cv_func_gettimeofday_clobber=yes],
92 dnl When crosscompiling, assume it is broken.
93 [gl_cv_func_gettimeofday_clobber=yes])])
95 if test $gl_cv_func_gettimeofday_clobber = yes; then
96 REPLACE_GETTIMEOFDAY=1
97 gl_GETTIMEOFDAY_REPLACE_LOCALTIME
98 AC_DEFINE([GETTIMEOFDAY_CLOBBERS_LOCALTIME], [1],
99 [Define if gettimeofday clobbers the localtime buffer.])
103 AC_DEFUN([gl_GETTIMEOFDAY_REPLACE_LOCALTIME], [
104 AC_LIBOBJ([gettimeofday])
105 gl_PREREQ_GETTIMEOFDAY
106 AC_DEFINE([gmtime], [rpl_gmtime],
107 [Define to rpl_gmtime if the replacement function should be used.])
108 AC_DEFINE([localtime], [rpl_localtime],
109 [Define to rpl_localtime if the replacement function should be used.])
112 # Prerequisites of lib/gettimeofday.c.
113 AC_DEFUN([gl_PREREQ_GETTIMEOFDAY], [
114 AC_CHECK_HEADERS([sys/timeb.h])
115 AC_CHECK_FUNCS([_ftime])