]> git.cworth.org Git - tar/blob - m4/sys_time_h.m4
Imported Upstream version 1.20
[tar] / m4 / sys_time_h.m4
1 # Configure a replacement for <sys/time.h>.
2
3 # Copyright (C) 2007 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 # Written by Paul Eggert and Martin Lambers.
9
10 AC_DEFUN([gl_HEADER_SYS_TIME_H],
11 [
12   dnl Use AC_REQUIRE here, so that the REPLACE_GETTIMEOFDAY=0 statement
13   dnl below is expanded once only, before all REPLACE_GETTIMEOFDAY=1
14   dnl statements that occur in other macros.
15   AC_REQUIRE([gl_HEADER_SYS_TIME_H_BODY])
16 ])
17
18 AC_DEFUN([gl_HEADER_SYS_TIME_H_BODY],
19 [
20   AC_REQUIRE([AC_C_RESTRICT])
21   gl_CHECK_NEXT_HEADERS([sys/time.h])
22
23   if test $ac_cv_header_sys_time_h = yes; then
24     HAVE_SYS_TIME_H=1
25   else
26     HAVE_SYS_TIME_H=0
27   fi
28   AC_SUBST([HAVE_SYS_TIME_H])
29
30   AC_CACHE_CHECK([for struct timeval], [gl_cv_sys_struct_timeval],
31     [AC_COMPILE_IFELSE(
32        [AC_LANG_PROGRAM(
33           [[#if HAVE_SYS_TIME_H
34              #include <sys/time.h>
35             #endif
36             #include <time.h>
37           ]],
38           [[static struct timeval x; x.tv_sec = x.tv_usec;]])],
39        [gl_cv_sys_struct_timeval=yes],
40        [gl_cv_sys_struct_timeval=no])])
41   if test $gl_cv_sys_struct_timeval = yes; then
42     HAVE_STRUCT_TIMEVAL=1
43   else
44     HAVE_STRUCT_TIMEVAL=0
45   fi
46   AC_SUBST([HAVE_STRUCT_TIMEVAL])
47
48   dnl Assume POSIX behavior unless another module says otherwise.
49   REPLACE_GETTIMEOFDAY=0
50   AC_SUBST([REPLACE_GETTIMEOFDAY])
51   if test $HAVE_SYS_TIME_H = 0 || test $HAVE_STRUCT_TIMEVAL = 0; then
52     SYS_TIME_H=sys/time.h
53   else
54     SYS_TIME_H=
55   fi
56   AC_SUBST([SYS_TIME_H])
57 ])