6b98dd73cc2d2c6fc8ab1f3ddcc2e1256ede4706
[gnulib.git] / m4 / stat-time.m4
1 # Checks for stat-related time functions.
2
3 # Copyright (C) 1998, 1999, 2001, 2003, 2005, 2006, 2007 Free Software
4 # Foundation, Inc.
5
6 # This file is free software; the Free Software Foundation
7 # gives unlimited permission to copy and/or distribute it,
8 # with or without modifications, as long as this notice is preserved.
9
10 dnl From Paul Eggert.
11
12 # st_atim.tv_nsec - Linux, Solaris
13 # st_atimespec.tv_nsec - FreeBSD, NetBSD, if ! defined _POSIX_SOURCE
14 # st_atimensec - FreeBSD, NetBSD, if defined _POSIX_SOURCE
15 # st_atim.st__tim.tv_nsec - UnixWare (at least 2.1.2 through 7.1)
16 # st_spare1 - Cygwin?
17
18 # st_birthtimespec present on NetBSD (probably also FreBSD, OpenBSD)
19
20 AC_DEFUN([gl_STAT_TIME],
21 [
22   AC_REQUIRE([AC_C_INLINE])
23   AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
24   AC_CHECK_HEADERS_ONCE([sys/time.h])
25
26   AC_CHECK_MEMBERS([struct stat.st_atim.tv_nsec],
27     [AC_CACHE_CHECK([whether struct stat.st_atim is of type struct timespec],
28        [ac_cv_typeof_struct_stat_st_atim_is_struct_timespec],
29        [AC_TRY_COMPILE(
30           [
31             #include <sys/types.h>
32             #include <sys/stat.h>
33             #if HAVE_SYS_TIME_H
34             # include <sys/time.h>
35             #endif
36             #include <time.h>
37             struct timespec ts;
38             struct stat st;
39           ],
40           [
41             st.st_atim = ts;
42           ],
43           [ac_cv_typeof_struct_stat_st_atim_is_struct_timespec=yes],
44           [ac_cv_typeof_struct_stat_st_atim_is_struct_timespec=no])])
45      if test $ac_cv_typeof_struct_stat_st_atim_is_struct_timespec = yes; then
46        AC_DEFINE([TYPEOF_STRUCT_STAT_ST_ATIM_IS_STRUCT_TIMESPEC], 1,
47          [Define to 1 if the type of the st_atim member of a struct stat is
48           struct timespec.])
49      fi],
50     [AC_CHECK_MEMBERS([struct stat.st_atimespec.tv_nsec], [],
51        [AC_CHECK_MEMBERS([struct stat.st_atimensec], [],
52           [AC_CHECK_MEMBERS([struct stat.st_atim.st__tim.tv_nsec], [],
53              [AC_CHECK_MEMBERS([struct stat.st_spare1], [],
54                 [],
55                 [#include <sys/types.h>
56                  #include <sys/stat.h>])],
57              [#include <sys/types.h>
58               #include <sys/stat.h>])],
59           [#include <sys/types.h>
60            #include <sys/stat.h>])],
61        [#include <sys/types.h>
62         #include <sys/stat.h>])],
63     [#include <sys/types.h>
64      #include <sys/stat.h>])
65 ])
66
67 # Checks for st_birthtime, which is a feature from UFS2 (FreeBSD, NetBSD, OpenBSD, etc.)
68 # There was a time when this field was named st_createtime (21 June 2002 to 16 July 2002)
69 # But that window is very small and applied only to development code, so systems still
70 # using that configuration are not a realistic development target.
71 # See revisions 1.10 and 1.11 of FreeBSD's src/sys/ufs/ufs/dinode.h.
72 #
73 AC_DEFUN([gl_STAT_BIRTHTIME],
74 [
75   AC_REQUIRE([AC_C_INLINE])
76   AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
77   AC_CHECK_HEADERS_ONCE([sys/time.h])
78   AC_CHECK_MEMBERS([struct stat.st_birthtimespec.tv_sec, struct stat.st_birthtimespec.tv_nsec], [],
79     [AC_CHECK_MEMBERS([struct stat.st_birthtime, struct stat.st_birthtimensec], [], 
80        [AC_CHECK_MEMBERS([struct stat.st_spare4], [], 
81            [],
82            [#include <sys/types.h>
83             #include <sys/stat.h>])],
84        [#include <sys/types.h>
85         #include <sys/stat.h>])],
86     [#include <sys/types.h>
87      #include <sys/stat.h>])
88 ])