Various fixes to Martin Lambers' gettimeofday patch.
[gnulib.git] / m4 / gettimeofday.m4
index e4d75da..51b916a 100644 (file)
@@ -1,14 +1,15 @@
 #serial 8
 
-# Copyright (C) 2001, 2002, 2003, 2005 Free Software Foundation, Inc.
+# Copyright (C) 2001, 2002, 2003, 2005, 2007 Free Software Foundation, Inc.
 # This file is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
 # with or without modifications, as long as this notice is preserved.
 
 AC_DEFUN([gl_FUNC_GETTIMEOFDAY],
 [
-  AC_LIBSOURCES([gettimeofday.c, gettimeofday.h])
-  AC_REQUIRE([gl_C_RESTRICT])
+  AC_REQUIRE([AC_C_RESTRICT])
+  AC_REQUIRE([AC_HEADER_TIME])
+  AC_CHECK_HEADERS_ONCE([sys/time.h])
   AC_CHECK_FUNCS([gettimeofday])
   
   AC_CHECK_TYPE([suseconds_t], ,
@@ -28,7 +29,7 @@ AC_DEFUN([gl_FUNC_GETTIMEOFDAY],
 #    endif
     ])
 
-  AC_CACHE_CHECK([for struct timeval], fu_cv_sys_struct_timeval,
+  AC_CACHE_CHECK([for struct timeval], [fu_cv_sys_struct_timeval],
     [AC_TRY_COMPILE(
       [
 #      if TIME_WITH_SYS_TIME
@@ -54,26 +55,25 @@ AC_DEFUN([gl_FUNC_GETTIMEOFDAY],
   
   AC_CACHE_CHECK([for gettimeofday whose signature conforms to POSIX],
     [ac_cv_func_gettimeofday_posix_signature],
-    AC_LINK_IFELSE(
-      [AC_LANG_PROGRAM(
-         [[#include <sys/time.h>
-          time_t a;
-          suseconds_t b;
-          struct timeval c;
-        ]],
-        [[
-          int x = gettimeofday (&c, 0);
-          int (*f) (struct timeval *restrict, void *restrict) = gettimeofday;
-          return !(x | c.tv_sec | c.tv_usec);
-        ]])],
+    [AC_LINK_IFELSE(
+       [AC_LANG_PROGRAM(
+          [[#include <sys/time.h>
+           time_t a;
+           suseconds_t b;
+           struct timeval c;
+         ]],
+         [[
+           int x = gettimeofday (&c, 0);
+           int (*f) (struct timeval *restrict, void *restrict) = gettimeofday;
+           return !(x | c.tv_sec | c.tv_usec);
+         ]])],
        [ac_cv_func_gettimeofday_posix_signature=yes],
-       [ac_cv_func_gettimeofday_posix_signature=no]))
+       [ac_cv_func_gettimeofday_posix_signature=no])])
   if test $ac_cv_func_gettimeofday_posix_signature = yes; then
     AC_DEFINE([HAVE_GETTIMEOFDAY_POSIX_SIGNATURE], 1,
       [Define if gettimeofday's signature conforms to POSIX.])
     AC_FUNC_GETTIMEOFDAY_CLOBBER
-  fi
-  if test $ac_cv_func_gettimeofday_posix_signature != yes; then
+  else
     gl_PREREQ_GETTIMEOFDAY
     AC_LIBOBJ([gettimeofday])
   fi
@@ -92,7 +92,7 @@ AC_DEFUN([AC_FUNC_GETTIMEOFDAY_CLOBBER],
 [
  AC_REQUIRE([AC_HEADER_TIME])
  AC_CACHE_CHECK([whether gettimeofday clobbers localtime buffer],
-  jm_cv_func_gettimeofday_clobber,
+  [jm_cv_func_gettimeofday_clobber],
   [AC_TRY_RUN([
 #include <stdio.h>
 #include <string.h>
@@ -133,21 +133,20 @@ main ()
   ])
   if test $jm_cv_func_gettimeofday_clobber = yes; then
     gl_GETTIMEOFDAY_REPLACE_LOCALTIME
-
-    AC_DEFINE(gettimeofday, rpl_gettimeofday,
-      [Define to rpl_gettimeofday if the replacement function should be used.])
   fi
 ])
 
 AC_DEFUN([gl_GETTIMEOFDAY_REPLACE_LOCALTIME], [
+  AC_LIBOBJ(gettimeofday)
   gl_PREREQ_GETTIMEOFDAY
-  AC_DEFINE(GETTIMEOFDAY_CLOBBERS_LOCALTIME, 1,
+  AC_DEFINE([GETTIMEOFDAY_CLOBBERS_LOCALTIME], 1,
     [Define if gettimeofday clobbers the localtime buffer.])
-  AC_LIBOBJ(gettimeofday)
-  AC_DEFINE(gmtime, rpl_gmtime,
+  AC_DEFINE([gmtime], [rpl_gmtime],
     [Define to rpl_gmtime if the replacement function should be used.])
-  AC_DEFINE(localtime, rpl_localtime,
+  AC_DEFINE([localtime], [rpl_localtime],
     [Define to rpl_localtime if the replacement function should be used.])
+  AC_DEFINE([tzset], [rpl_tzset],
+    [Define to rpl_tzset if the replacement function should be used.])
 ])
 
 # Prerequisites of lib/gettimeofday.c.