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
10AC_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
18AC_DEFUN([gl_HEADER_SYS_TIME_H_BODY],
19[
20  AC_REQUIRE([AC_C_RESTRICT])
21  AC_CHECK_HEADERS_ONCE([sys/time.h])
22
23  if test $ac_cv_header_sys_time_h = yes; then
24    gl_ABSOLUTE_HEADER([sys/time.h])
25    ABSOLUTE_SYS_TIME_H=\"$gl_cv_absolute_sys_time_h\"
26    HAVE_SYS_TIME_H=1
27  else
28    ABSOLUTE_SYS_TIME_H=\"no/such/file/sys/time.h\"
29    HAVE_SYS_TIME_H=0
30  fi
31  AC_SUBST([ABSOLUTE_SYS_TIME_H])
32  AC_SUBST([HAVE_SYS_TIME_H])
33
34  AC_CACHE_CHECK([for struct timeval], [gl_cv_sys_struct_timeval],
35    [AC_COMPILE_IFELSE(
36       [AC_LANG_PROGRAM(
37	  [[#if HAVE_SYS_TIME_H
38	     #include <sys/time.h>
39	    #endif
40	    #include <time.h>
41	  ]],
42	  [[static struct timeval x; x.tv_sec = x.tv_usec;]])],
43       [gl_cv_sys_struct_timeval=yes],
44       [gl_cv_sys_struct_timeval=no])])
45  if test $gl_cv_sys_struct_timeval = yes; then
46    HAVE_STRUCT_TIMEVAL=1
47  else
48    HAVE_STRUCT_TIMEVAL=0
49  fi
50  AC_SUBST([HAVE_STRUCT_TIMEVAL])
51
52  dnl Assume POSIX behavior unless another module says otherwise.
53  REPLACE_GETTIMEOFDAY=0
54  AC_SUBST([REPLACE_GETTIMEOFDAY])
55  if test $HAVE_SYS_TIME_H = 0 || test $HAVE_STRUCT_TIMEVAL = 0; then
56    SYS_TIME_H=sys/time.h
57  else
58    SYS_TIME_H=
59  fi
60  AC_SUBST([SYS_TIME_H])
61])
62