Following Björn JACKE's patch, unify the detection of the timespec code in configure...
authorJeremy Allison <jra@samba.org>
Thu, 29 Jan 2009 18:47:02 +0000 (10:47 -0800)
committerJeremy Allison <jra@samba.org>
Thu, 29 Jan 2009 18:48:16 +0000 (10:48 -0800)
Jeremy.

source/configure.in
source/lib/time.c

index 11fea8f9adbe0e9e09f9aa944bb15632c87d1ad9..215b21964c50c4aa71e575b122810abb658a2a28 100644 (file)
@@ -1278,7 +1278,8 @@ fi
 
 #################################################
 # Check whether struct stat has timestamps with sub-second resolution.
-# At least IRIX and Solaris have these.
+# At least IRIX and Solaris have these.  FREEBSD does as well,
+# but with different members
 #
 # We check that
 #      all of st_mtim, st_atim and st_ctim exist
@@ -1287,6 +1288,43 @@ fi
 # There is some conflicting standards weirdness about whether we should use
 # "struct timespec" or "timespec_t". Linux doesn't have timespec_t, so we
 # prefer struct timespec.
+AC_CACHE_CHECK([whether struct stat has timespec timestamps],
+    samba_cv_stat_timespec_hires,
+      [
+      AC_TRY_COMPILE(
+         [
+#if TIME_WITH_SYS_TIME
+# include <sys/time.h>
+# include <time.h>
+#else
+# if HAVE_SYS_TIME_H
+#  include <sys/time.h>
+# else
+#  include <time.h>
+# endif
+#endif
+#ifdef HAVE_SYS_STAT_H
+#include <sys/stat.h>
+#endif
+         ],
+         [
+         struct timespec t;
+         struct stat s = {0};
+         t = s.st_mtimespec;
+         t = s.st_ctimespec;
+         t = s.st_atimespec;
+       ],
+      samba_cv_stat_timespec_hires=yes, samba_cv_stat_timespec_hires=no)
+      ])
+
+if test x"$samba_cv_stat_timespec_hires" = x"yes" ; then
+    AC_DEFINE(HAVE_STAT_ST_MTIMESPEC, 1, [whether struct stat contains st_mtimepec])
+    AC_DEFINE(HAVE_STAT_ST_ATIMESPEC, 1, [whether struct stat contains st_atimespec])
+    AC_DEFINE(HAVE_STAT_ST_CTIMESPEC, 1, [whether struct stat contains st_ctimespec])
+    AC_DEFINE(HAVE_STAT_HIRES_TIMESTAMPS, 1, [whether struct stat has sub-second timestamps])
+fi
+
+
 
 AC_CACHE_CHECK([whether struct stat has sub-second timestamps], samba_cv_stat_hires,
     [
index 425539c3b0d4ea32db9af86b530e8054676d47d8..3ff601a515780063806bba51b7117d40274632cc 100644 (file)
@@ -903,6 +903,13 @@ struct timespec get_atimespec(const SMB_STRUCT_STAT *pst)
        ret.tv_sec = pst->st_atime;
        ret.tv_nsec = pst->st_atimensec;
        return ret;
+#elif defined(HAVE_STAT_ST_ATIME_N)
+       struct timespec ret;
+       ret.tv_sec = pst->st_atime;
+       ret.tv_nsec = pst->st_atime_n;
+       return ret;
+#elif defined(HAVE_STAT_ST_ATIMESPEC)
+       return pst->st_atimespec;
 #else
 #error CONFIGURE_ERROR_IN_DETECTING_TIMESPEC_IN_STAT 
 #endif
@@ -920,6 +927,11 @@ void set_atimespec(SMB_STRUCT_STAT *pst, struct timespec ts)
 #elif defined(HAVE_STAT_ST_ATIMENSEC)
        pst->st_atime = ts.tv_sec;
        pst->st_atimensec = ts.tv_nsec
+#elif defined(HAVE_STAT_ST_ATIME_N)
+       pst->st_atime = ts.tv_sec;
+       pst->st_atime_n = ts.tv_nsec
+#elif defined(HAVE_STAT_ST_ATIMESPEC)
+       pst->st_atimespec = ts;
 #else
 #error CONFIGURE_ERROR_IN_DETECTING_TIMESPEC_IN_STAT 
 #endif
@@ -943,6 +955,13 @@ struct timespec get_mtimespec(const SMB_STRUCT_STAT *pst)
        ret.tv_sec = pst->st_mtime;
        ret.tv_nsec = pst->st_mtimensec;
        return ret;
+#elif defined(HAVE_STAT_ST_MTIME_N)
+       struct timespec ret;
+       ret.tv_sec = pst->st_mtime;
+       ret.tv_nsec = pst->st_mtime_n;
+       return ret;
+#elif defined(HAVE_STAT_ST_MTIMESPEC)
+       return pst->st_mtimespec;
 #else
 #error CONFIGURE_ERROR_IN_DETECTING_TIMESPEC_IN_STAT 
 #endif
@@ -960,6 +979,11 @@ void set_mtimespec(SMB_STRUCT_STAT *pst, struct timespec ts)
 #elif defined(HAVE_STAT_ST_MTIMENSEC)
        pst->st_mtime = ts.tv_sec;
        pst->st_mtimensec = ts.tv_nsec
+#elif defined(HAVE_STAT_ST_MTIME_N)
+       pst->st_mtime = ts.tv_sec;
+       pst->st_mtime_n = ts.tv_nsec
+#elif defined(HAVE_STAT_ST_MTIMESPEC)
+       pst->st_mtimespec = ts;
 #else
 #error CONFIGURE_ERROR_IN_DETECTING_TIMESPEC_IN_STAT 
 #endif
@@ -983,6 +1007,13 @@ struct timespec get_ctimespec(const SMB_STRUCT_STAT *pst)
        ret.tv_sec = pst->st_ctime;
        ret.tv_nsec = pst->st_ctimensec;
        return ret;
+#elif defined(HAVE_STAT_ST_CTIME_N)
+       struct timespec ret;
+       ret.tv_sec = pst->st_ctime;
+       ret.tv_nsec = pst->st_ctime_n;
+       return ret;
+#elif defined(HAVE_STAT_ST_CTIMESPEC)
+       return pst->st_ctimespec;
 #else
 #error CONFIGURE_ERROR_IN_DETECTING_TIMESPEC_IN_STAT 
 #endif
@@ -1000,6 +1031,11 @@ void set_ctimespec(SMB_STRUCT_STAT *pst, struct timespec ts)
 #elif defined(HAVE_STAT_ST_CTIMENSEC)
        pst->st_ctime = ts.tv_sec;
        pst->st_ctimensec = ts.tv_nsec
+#elif defined(HAVE_STAT_ST_CTIME_N)
+       pst->st_ctime = ts.tv_sec;
+       pst->st_ctime_n = ts.tv_nsec
+#elif defined(HAVE_STAT_ST_CTIMESPEC)
+       pst->st_ctimespec = ts;
 #else
 #error CONFIGURE_ERROR_IN_DETECTING_TIMESPEC_IN_STAT 
 #endif