~ubuntu-branches/ubuntu/natty/diffutils/natty

« back to all changes in this revision

Viewing changes to m4/gettimeofday.m4

  • Committer: Bazaar Package Importer
  • Author(s): Santiago Vila
  • Date: 2010-05-04 20:38:00 UTC
  • mfrom: (2.1.7 sid)
  • Revision ID: james.westby@ubuntu.com-20100504203800-f67xd9rsa9xl9qqj
Tags: 1:3.0-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# serial 15
 
2
 
 
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.
 
7
 
 
8
dnl From Jim Meyering.
 
9
 
 
10
AC_DEFUN([gl_FUNC_GETTIMEOFDAY],
 
11
[
 
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])
 
16
 
 
17
  gl_gettimeofday_timezone=void
 
18
  if test $ac_cv_func_gettimeofday != yes; then
 
19
    HAVE_GETTIMEOFDAY=0
 
20
    AC_LIBOBJ([gettimeofday])
 
21
    gl_PREREQ_GETTIMEOFDAY
 
22
  else
 
23
    gl_FUNC_GETTIMEOFDAY_CLOBBER
 
24
    AC_CACHE_CHECK([for gettimeofday with POSIX signature],
 
25
      [gl_cv_func_gettimeofday_posix_signature],
 
26
      [AC_COMPILE_IFELSE(
 
27
         [AC_LANG_PROGRAM(
 
28
            [[#include <sys/time.h>
 
29
              struct timeval c;
 
30
              int gettimeofday (struct timeval *restrict, void *restrict);
 
31
            ]],
 
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)
 
38
                = gettimeofday;
 
39
              int x = f (&c, 0);
 
40
              return !(x | c.tv_sec | c.tv_usec);
 
41
            ]])],
 
42
          [gl_cv_func_gettimeofday_posix_signature=yes],
 
43
          [AC_COMPILE_IFELSE(
 
44
            [AC_LANG_PROGRAM(
 
45
              [[#include <sys/time.h>
 
46
int gettimeofday (struct timeval *restrict, struct timezone *restrict);
 
47
              ]])],
 
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
 
56
    fi
 
57
  fi
 
58
  AC_DEFINE_UNQUOTED([GETTIMEOFDAY_TIMEZONE], [$gl_gettimeofday_timezone],
 
59
    [Define this to 'void' or 'struct timezone' to match the system's
 
60
     declaration of the second argument to gettimeofday.])
 
61
])
 
62
 
 
63
 
 
64
dnl See if gettimeofday clobbers the static buffer that localtime uses
 
65
dnl for its return value.  The gettimeofday function from Mac OS X 10.0.4
 
66
dnl (i.e., Darwin 1.3.7) has this problem.
 
67
dnl
 
68
dnl If it does, then arrange to use gettimeofday and localtime only via
 
69
dnl the wrapper functions that work around the problem.
 
70
 
 
71
AC_DEFUN([gl_FUNC_GETTIMEOFDAY_CLOBBER],
 
72
[
 
73
 AC_REQUIRE([gl_HEADER_SYS_TIME_H])
 
74
 
 
75
 AC_CACHE_CHECK([whether gettimeofday clobbers localtime buffer],
 
76
  [gl_cv_func_gettimeofday_clobber],
 
77
  [AC_RUN_IFELSE(
 
78
     [AC_LANG_PROGRAM(
 
79
        [[#include <string.h>
 
80
          #include <sys/time.h>
 
81
          #include <time.h>
 
82
          #include <stdlib.h>
 
83
        ]],
 
84
        [[
 
85
          time_t t = 0;
 
86
          struct tm *lt;
 
87
          struct tm saved_lt;
 
88
          struct timeval tv;
 
89
          lt = localtime (&t);
 
90
          saved_lt = *lt;
 
91
          gettimeofday (&tv, NULL);
 
92
          return memcmp (lt, &saved_lt, sizeof (struct tm)) != 0;
 
93
        ]])],
 
94
     [gl_cv_func_gettimeofday_clobber=no],
 
95
     [gl_cv_func_gettimeofday_clobber=yes],
 
96
     dnl When crosscompiling, assume it is broken.
 
97
     [gl_cv_func_gettimeofday_clobber=yes])])
 
98
 
 
99
 if test $gl_cv_func_gettimeofday_clobber = yes; then
 
100
   REPLACE_GETTIMEOFDAY=1
 
101
   gl_GETTIMEOFDAY_REPLACE_LOCALTIME
 
102
   AC_DEFINE([GETTIMEOFDAY_CLOBBERS_LOCALTIME], [1],
 
103
     [Define if gettimeofday clobbers the localtime buffer.])
 
104
 fi
 
105
])
 
106
 
 
107
AC_DEFUN([gl_GETTIMEOFDAY_REPLACE_LOCALTIME], [
 
108
  AC_LIBOBJ([gettimeofday])
 
109
  gl_PREREQ_GETTIMEOFDAY
 
110
  AC_DEFINE([gmtime], [rpl_gmtime],
 
111
    [Define to rpl_gmtime if the replacement function should be used.])
 
112
  AC_DEFINE([localtime], [rpl_localtime],
 
113
    [Define to rpl_localtime if the replacement function should be used.])
 
114
])
 
115
 
 
116
# Prerequisites of lib/gettimeofday.c.
 
117
AC_DEFUN([gl_PREREQ_GETTIMEOFDAY], [
 
118
  AC_CHECK_HEADERS([sys/timeb.h])
 
119
  AC_CHECK_FUNCS([_ftime])
 
120
])