3 # Copyright (C) 2001-2003, 2005, 2007, 2009-2015 Free Software
5 # This file is free software; the Free Software Foundation
6 # gives unlimited permission to copy and/or distribute it,
7 # with or without modifications, as long as this notice is preserved.
11 AC_DEFUN([gl_FUNC_GETTIMEOFDAY],
13 AC_REQUIRE([AC_C_RESTRICT])
14 AC_REQUIRE([gl_HEADER_SYS_TIME_H])
15 AC_REQUIRE([gl_HEADER_SYS_TIME_H_DEFAULTS])
16 AC_CHECK_FUNCS_ONCE([gettimeofday])
18 gl_gettimeofday_timezone=void
19 if test $ac_cv_func_gettimeofday != yes; then
22 gl_FUNC_GETTIMEOFDAY_CLOBBER
23 AC_CACHE_CHECK([for gettimeofday with POSIX signature],
24 [gl_cv_func_gettimeofday_posix_signature],
27 [[#include <sys/time.h>
29 int gettimeofday (struct timeval *restrict, void *restrict);
31 [[/* glibc uses struct timezone * rather than the POSIX void *
32 if _GNU_SOURCE is defined. However, since the only portable
33 use of gettimeofday uses NULL as the second parameter, and
34 since the glibc definition is actually more typesafe, it is
35 not worth wrapping this to get a compliant signature. */
36 int (*f) (struct timeval *restrict, void *restrict)
39 return !(x | c.tv_sec | c.tv_usec);
41 [gl_cv_func_gettimeofday_posix_signature=yes],
44 [[#include <sys/time.h>
45 int gettimeofday (struct timeval *restrict, struct timezone *restrict);
47 [gl_cv_func_gettimeofday_posix_signature=almost],
48 [gl_cv_func_gettimeofday_posix_signature=no])])])
49 if test $gl_cv_func_gettimeofday_posix_signature = almost; then
50 gl_gettimeofday_timezone='struct timezone'
51 elif test $gl_cv_func_gettimeofday_posix_signature != yes; then
52 REPLACE_GETTIMEOFDAY=1
54 dnl If we override 'struct timeval', we also have to override gettimeofday.
55 if test $REPLACE_STRUCT_TIMEVAL = 1; then
56 REPLACE_GETTIMEOFDAY=1
58 m4_ifdef([gl_FUNC_TZSET_CLOBBER], [
60 case "$gl_cv_func_tzset_clobber" in
62 REPLACE_GETTIMEOFDAY=1
63 gl_GETTIMEOFDAY_REPLACE_LOCALTIME
64 AC_DEFINE([tzset], [rpl_tzset],
65 [Define to rpl_tzset if the wrapper function should be used.])
66 AC_DEFINE([TZSET_CLOBBERS_LOCALTIME], [1],
67 [Define if tzset clobbers localtime's static buffer.])
72 AC_DEFINE_UNQUOTED([GETTIMEOFDAY_TIMEZONE], [$gl_gettimeofday_timezone],
73 [Define this to 'void' or 'struct timezone' to match the system's
74 declaration of the second argument to gettimeofday.])
78 dnl See if gettimeofday clobbers the static buffer that localtime uses
79 dnl for its return value. The gettimeofday function from Mac OS X 10.0.4
80 dnl (i.e., Darwin 1.3.7) has this problem.
82 dnl If it does, then arrange to use gettimeofday and localtime only via
83 dnl the wrapper functions that work around the problem.
85 AC_DEFUN([gl_FUNC_GETTIMEOFDAY_CLOBBER],
87 AC_REQUIRE([gl_HEADER_SYS_TIME_H])
88 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
90 AC_CACHE_CHECK([whether gettimeofday clobbers localtime buffer],
91 [gl_cv_func_gettimeofday_clobber],
106 gettimeofday (&tv, NULL);
107 return memcmp (lt, &saved_lt, sizeof (struct tm)) != 0;
109 [gl_cv_func_gettimeofday_clobber=no],
110 [gl_cv_func_gettimeofday_clobber=yes],
111 [# When cross-compiling:
113 # Guess all is fine on glibc systems.
114 *-gnu*) gl_cv_func_gettimeofday_clobber="guessing no" ;;
115 # If we don't know, assume the worst.
116 *) gl_cv_func_gettimeofday_clobber="guessing yes" ;;
120 case "$gl_cv_func_gettimeofday_clobber" in
122 REPLACE_GETTIMEOFDAY=1
123 gl_GETTIMEOFDAY_REPLACE_LOCALTIME
124 AC_DEFINE([GETTIMEOFDAY_CLOBBERS_LOCALTIME], [1],
125 [Define if gettimeofday clobbers the localtime buffer.])
130 AC_DEFUN([gl_GETTIMEOFDAY_REPLACE_LOCALTIME], [
135 # Prerequisites of lib/gettimeofday.c.
136 AC_DEFUN([gl_PREREQ_GETTIMEOFDAY], [
137 AC_CHECK_HEADERS([sys/timeb.h])
138 AC_CHECK_FUNCS([_ftime])