3 # Copyright (C) 2001-2003, 2005, 2007, 2009-2011 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
20 AC_LIBOBJ([gettimeofday])
21 gl_PREREQ_GETTIMEOFDAY
23 gl_FUNC_GETTIMEOFDAY_CLOBBER
24 AC_CACHE_CHECK([for gettimeofday with POSIX signature],
25 [gl_cv_func_gettimeofday_posix_signature],
28 [[#include <sys/time.h>
30 int gettimeofday (struct timeval *restrict, void *restrict);
32 [[/* glibc uses struct timezone * rather than the POSIX void *
33 if _GNU_SOURCE is defined. However, since the only portable
34 use of gettimeofday uses NULL as the second parameter, and
35 since the glibc definition is actually more typesafe, it is
36 not worth wrapping this to get a compliant signature. */
37 int (*f) (struct timeval *restrict, void *restrict)
40 return !(x | c.tv_sec | c.tv_usec);
42 [gl_cv_func_gettimeofday_posix_signature=yes],
45 [[#include <sys/time.h>
46 int gettimeofday (struct timeval *restrict, struct timezone *restrict);
48 [gl_cv_func_gettimeofday_posix_signature=almost],
49 [gl_cv_func_gettimeofday_posix_signature=no])])])
50 if test $gl_cv_func_gettimeofday_posix_signature = almost; then
51 gl_gettimeofday_timezone='struct timezone'
52 elif test $gl_cv_func_gettimeofday_posix_signature != yes; then
53 REPLACE_GETTIMEOFDAY=1
54 AC_LIBOBJ([gettimeofday])
55 gl_PREREQ_GETTIMEOFDAY
57 m4_ifdef([gl_FUNC_TZSET_CLOBBER], [
59 if test $gl_cv_func_tzset_clobber = yes; then
60 REPLACE_GETTIMEOFDAY=1
61 gl_GETTIMEOFDAY_REPLACE_LOCALTIME
62 AC_DEFINE([tzset], [rpl_tzset],
63 [Define to rpl_tzset if the wrapper function should be used.])
64 AC_DEFINE([TZSET_CLOBBERS_LOCALTIME], [1],
65 [Define if tzset clobbers localtime's static buffer.])
69 AC_DEFINE_UNQUOTED([GETTIMEOFDAY_TIMEZONE], [$gl_gettimeofday_timezone],
70 [Define this to 'void' or 'struct timezone' to match the system's
71 declaration of the second argument to gettimeofday.])
75 dnl See if gettimeofday clobbers the static buffer that localtime uses
76 dnl for its return value. The gettimeofday function from Mac OS X 10.0.4
77 dnl (i.e., Darwin 1.3.7) has this problem.
79 dnl If it does, then arrange to use gettimeofday and localtime only via
80 dnl the wrapper functions that work around the problem.
82 AC_DEFUN([gl_FUNC_GETTIMEOFDAY_CLOBBER],
84 AC_REQUIRE([gl_HEADER_SYS_TIME_H])
86 AC_CACHE_CHECK([whether gettimeofday clobbers localtime buffer],
87 [gl_cv_func_gettimeofday_clobber],
102 gettimeofday (&tv, NULL);
103 return memcmp (lt, &saved_lt, sizeof (struct tm)) != 0;
105 [gl_cv_func_gettimeofday_clobber=no],
106 [gl_cv_func_gettimeofday_clobber=yes],
107 dnl When crosscompiling, assume it is broken.
108 [gl_cv_func_gettimeofday_clobber=yes])])
110 if test $gl_cv_func_gettimeofday_clobber = yes; then
111 REPLACE_GETTIMEOFDAY=1
112 gl_GETTIMEOFDAY_REPLACE_LOCALTIME
113 AC_DEFINE([GETTIMEOFDAY_CLOBBERS_LOCALTIME], [1],
114 [Define if gettimeofday clobbers the localtime buffer.])
118 AC_DEFUN([gl_GETTIMEOFDAY_REPLACE_LOCALTIME], [
119 AC_LIBOBJ([gettimeofday])
120 gl_PREREQ_GETTIMEOFDAY
121 AC_DEFINE([gmtime], [rpl_gmtime],
122 [Define to rpl_gmtime if the replacement function should be used.])
123 AC_DEFINE([localtime], [rpl_localtime],
124 [Define to rpl_localtime if the replacement function should be used.])
127 # Prerequisites of lib/gettimeofday.c.
128 AC_DEFUN([gl_PREREQ_GETTIMEOFDAY], [
129 AC_CHECK_HEADERS([sys/timeb.h])
130 AC_CHECK_FUNCS([_ftime])