Require AC_HEADER_TIME, and include sys/time.h as well
[gnulib.git] / m4 / timespec.m4
1 #serial 3
2
3 dnl From Jim Meyering
4
5 dnl Define HAVE_STRUCT_TIMESPEC if `struct timespec' is declared
6 dnl in time.h or sys/time.h.
7
8 AC_DEFUN(jm_CHECK_TYPE_STRUCT_TIMESPEC,
9 [
10   AC_CACHE_CHECK([for struct timespec], fu_cv_sys_struct_timespec,
11    AC_REQUIRE([AC_HEADER_TIME])
12     [AC_TRY_COMPILE(
13       [
14 #      if TIME_WITH_SYS_TIME
15 #       include <sys/time.h>
16 #       include <time.h>
17 #      else
18 #       if HAVE_SYS_TIME_H
19 #        include <sys/time.h>
20 #       else
21 #        include <time.h>
22 #       endif
23 #      endif
24       ],
25       [static struct timespec x; x.tv_sec = x.tv_nsec;],
26       fu_cv_sys_struct_timespec=yes,
27       fu_cv_sys_struct_timespec=no)
28     ])
29
30   if test $fu_cv_sys_struct_timespec = yes; then
31     AC_DEFINE_UNQUOTED(HAVE_STRUCT_TIMESPEC, 1,
32                        [Define if struct timespec is declared in <time.h>. ])
33   fi
34 ])