diff options
author | Björn Jacke <bj@sernet.de> | 2009-02-11 21:19:01 +0100 |
---|---|---|
committer | Volker Lendecke <vl@samba.org> | 2009-02-12 13:00:44 +0100 |
commit | 263b798db9bd6c26a51fbf38e4d5d693d234fa5f (patch) | |
tree | 291241189f9c636fa1ec4f6ef5cee4ab4b9b386e | |
parent | aff48fba1825b2838818ab2f1d037fae32ae132a (diff) | |
download | samba-263b798db9bd6c26a51fbf38e4d5d693d234fa5f.tar.gz samba-263b798db9bd6c26a51fbf38e4d5d693d234fa5f.tar.bz2 samba-263b798db9bd6c26a51fbf38e4d5d693d234fa5f.zip |
tidy up timestamp checks
AC_CHECK_MEMBERS should be a sufficient check, there's no need to do manual
compile tests. We can also assume that we have ctime and atime members when we
have the mtime member.
-rw-r--r-- | source3/configure.in | 300 | ||||
-rw-r--r-- | source3/lib/time.c | 66 |
2 files changed, 47 insertions, 319 deletions
diff --git a/source3/configure.in b/source3/configure.in index 8e49074533..46e863a14d 100644 --- a/source3/configure.in +++ b/source3/configure.in @@ -1299,301 +1299,29 @@ fi ################################################# # Check whether struct stat has timestamps with sub-second resolution. -# 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 -# all of the members are in fact of type struct timespec -# -# 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, - [ - 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.tv_sec = s.st_mtim.tv_sec; - t.tv_nsec = s.st_mtim.tv_nsec; - t.tv_sec = s.st_ctim.tv_sec; - t.tv_nsec = s.st_ctim.tv_nsec; - t.tv_sec = s.st_atim.tv_sec; - t.tv_nsec = s.st_atim.tv_nsec; - ], - samba_cv_stat_hires=yes, samba_cv_stat_hires=no) - ]) +samba_cv_stat_hires=no +AC_CHECK_MEMBERS([struct stat.st_mtim.tv_nsec], # Linux, Solaris + [samba_cv_stat_hires=yes]) +AC_CHECK_MEMBERS([struct stat.st_mtimensec], # BSD, if defined _POSIX_SOURCE + [samba_cv_stat_hires=yes]) +AC_CHECK_MEMBERS([struct stat.st_mtimespec.tv_nsec], # BSD, if not defined _POSIX_SOURCE + [samba_cv_stat_hires=yes]) +AC_CHECK_MEMBERS([struct stat.st_mtime_n], # AIX + [samba_cv_stat_hires=yes]) +AC_CHECK_MEMBERS([struct stat.st_umtime], # Tru64 + [samba_cv_stat_hires=yes]) if test x"$samba_cv_stat_hires" = x"yes" ; then - AC_DEFINE(HAVE_STAT_ST_MTIM, 1, [whether struct stat contains st_mtim]) - AC_DEFINE(HAVE_STAT_ST_ATIM, 1, [whether struct stat contains st_atim]) - AC_DEFINE(HAVE_STAT_ST_CTIM, 1, [whether struct stat contains st_ctim]) 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 without struct timespec suffixed nsec], samba_cv_stat_hires_notimespec, - [ - 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.tv_sec = s.st_mtime; - t.tv_nsec = s.st_mtimensec; - t.tv_sec = s.st_ctime; - t.tv_nsec = s.st_ctimensec; - t.tv_sec = s.st_atime; - t.tv_nsec = s.st_atimensec; - ], - samba_cv_stat_hires_notimespec=yes, samba_cv_stat_hires_notimespec=no) - ]) - -if test x"$samba_cv_stat_hires_notimespec" = x"yes" ; then - AC_DEFINE(HAVE_STAT_ST_MTIMENSEC, 1, [whether struct stat contains st_mtimensec]) - AC_DEFINE(HAVE_STAT_ST_ATIMENSEC, 1, [whether struct stat contains st_atimensec]) - AC_DEFINE(HAVE_STAT_ST_CTIMENSEC, 1, [whether struct stat contains st_ctimensec]) - AC_DEFINE(HAVE_STAT_HIRES_TIMESTAMPS, 1, - [whether struct stat has sub-second timestamps without struct timespec suffixed nsec]) -fi - -dnl AIX stype sub-second timestamps: -AC_CACHE_CHECK([whether struct stat has sub-second timestamps without struct timespec suffixed _n], samba_cv_stat_hires_notimespec_n, - [ - 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.tv_sec = s.st_mtime; - t.tv_nsec = s.st_mtime_n; - t.tv_sec = s.st_ctime; - t.tv_nsec = s.st_ctime_n; - t.tv_sec = s.st_atime; - t.tv_nsec = s.st_atime_n; - ], - samba_cv_stat_hires_notimespec_n=yes, samba_cv_stat_hires_notimespec_n=no) - ]) - -if test x"$samba_cv_stat_hires_notimespec_n" = x"yes" ; then - AC_DEFINE(HAVE_STAT_ST_MTIME_N, 1, [whether struct stat contains st_mtime_n]) - AC_DEFINE(HAVE_STAT_ST_ATIME_N, 1, [whether struct stat contains st_atime_n]) - AC_DEFINE(HAVE_STAT_ST_CTIME_N, 1, [whether struct stat contains st_ctime_n]) - AC_DEFINE(HAVE_STAT_HIRES_TIMESTAMPS, 1, - [whether struct stat has sub-second timestamps without struct timespec suffixed _n]) -fi - -dnl Tru64 has _micro_second_ resolution: -AC_CACHE_CHECK([whether struct stat has sub-second timestamps in st_uXtime], samba_cv_stat_hires_uxtime, - [ - 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.tv_sec = s.st_mtime; - t.tv_nsec = s.st_umtime * 1000; - t.tv_sec = s.st_ctime; - t.tv_nsec = s.st_uctime * 1000; - t.tv_sec = s.st_atime; - t.tv_nsec = s.st_uatime * 1000; - ], - samba_cv_stat_hires_uxtime=yes, samba_cv_stat_hires_uxtime=no) - ]) - -if test x"$samba_cv_stat_hires_uxtime" = x"yes" ; then - AC_DEFINE(HAVE_STAT_ST_UMTIME, 1, [whether struct stat contains st_umtime]) - AC_DEFINE(HAVE_STAT_ST_UATIME, 1, [whether struct stat contains st_uatime]) - AC_DEFINE(HAVE_STAT_ST_UCTIME, 1, [whether struct stat contains st_uctime]) - AC_DEFINE(HAVE_STAT_HIRES_TIMESTAMPS, 1, - [whether struct stat has sub-second timestamps in st_uXtime]) -fi - -AC_CACHE_CHECK([whether struct stat has st_birthtimespec], samba_cv_stat_st_birthtimespec, - [ - 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_birthtimespec; - ], - samba_cv_stat_st_birthtimespec=yes, samba_cv_stat_st_birthtimespec=no) - ]) - -if test x"$samba_cv_stat_st_birthtimespec" = x"yes" ; then - AC_DEFINE(HAVE_STAT_ST_BIRTHTIMESPEC, 1, [whether struct stat contains st_birthtimespec]) -fi - -AC_CACHE_CHECK([whether struct stat has st_birthtimensec], samba_cv_stat_st_birthtimensec, - [ - 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.tv_nsec = s.st_birthtimensec; - ], - samba_cv_stat_st_birthtimensec=yes, samba_cv_stat_st_birthtimensec=no) - ]) - -if test x"$samba_cv_stat_st_birthtimensec" = x"yes" ; then - AC_DEFINE(HAVE_STAT_ST_BIRTHTIMENSEC, 1, [whether struct stat contains st_birthtimensec]) -fi +# recent FreeBSD, NetBSD have creation timestamps called birthtime: +AC_CHECK_MEMBERS([struct stat.st_birthtimespec.tv_nsec]) +AC_CHECK_MEMBERS([struct stat.st_birthtime], AC_CHECK_MEMBERS([struct stat.st_birthtimensec])) -AC_CACHE_CHECK([whether struct stat has st_birthtime], samba_cv_stat_st_birthtime, - [ - 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 time_t t; - struct stat s = {0}; - t = s.st_birthtime; - ], - samba_cv_stat_st_birthtime=yes, samba_cv_stat_st_birthtime=no) - ]) - -if test x"$samba_cv_stat_st_birthtime" = x"yes" ; then - AC_DEFINE(HAVE_STAT_ST_BIRTHTIME, 1, [whether struct stat contains st_birthtime]) -fi AC_CACHE_CHECK([whether there is DOS flags support in the stat struct], samba_cv_stat_dos_flags, [ diff --git a/source3/lib/time.c b/source3/lib/time.c index e2cfe687b2..865456b23b 100644 --- a/source3/lib/time.c +++ b/source3/lib/time.c @@ -360,12 +360,12 @@ struct timespec get_create_timespec(const SMB_STRUCT_STAT *pst,bool fake_dirs) return ret; } -#if defined(HAVE_STAT_ST_BIRTHTIMESPEC) +#if defined(HAVE_STRUCT_STAT_ST_BIRTHTIMESPEC_TV_NSEC) ret = pst->st_birthtimespec; -#elif defined(HAVE_STAT_ST_BIRTHTIMENSEC) +#elif defined(HAVE_STRUCT_STAT_ST_BIRTHTIMENSEC) ret.tv_sec = pst->st_birthtime; ret.tv_nsec = pst->st_birthtimenspec; -#elif defined(HAVE_STAT_ST_BIRTHTIME) +#elif defined(HAVE_STRUCT_STAT_ST_BIRTHTIME) ret.tv_sec = pst->st_birthtime; ret.tv_nsec = 0; #else @@ -397,24 +397,24 @@ struct timespec get_atimespec(const SMB_STRUCT_STAT *pst) ret.tv_nsec = 0; return ret; #else -#if defined(HAVE_STAT_ST_ATIM) +#if defined(HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC) return pst->st_atim; -#elif defined(HAVE_STAT_ST_ATIMENSEC) +#elif defined(HAVE_STRUCT_STAT_ST_MTIMENSEC) struct timespec ret; ret.tv_sec = pst->st_atime; ret.tv_nsec = pst->st_atimensec; return ret; -#elif defined(HAVE_STAT_ST_ATIME_N) +#elif defined(HAVE_STRUCT_STAT_ST_MTIME_N) struct timespec ret; ret.tv_sec = pst->st_atime; ret.tv_nsec = pst->st_atime_n; return ret; -#elif defined(HAVE_STAT_ST_UATIME) +#elif defined(HAVE_STRUCT_STAT_ST_UMTIME) struct timespec ret; ret.tv_sec = pst->st_atime; ret.tv_nsec = pst->st_uatime * 1000; return ret; -#elif defined(HAVE_STAT_ST_ATIMESPEC) +#elif defined(HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC) return pst->st_atimespec; #else #error CONFIGURE_ERROR_IN_DETECTING_TIMESPEC_IN_STAT @@ -428,18 +428,18 @@ void set_atimespec(SMB_STRUCT_STAT *pst, struct timespec ts) /* Old system - no ns timestamp. */ pst->st_atime = ts.tv_sec; #else -#if defined(HAVE_STAT_ST_ATIM) +#if defined(HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC) pst->st_atim = ts; -#elif defined(HAVE_STAT_ST_ATIMENSEC) +#elif defined(HAVE_STRUCT_STAT_ST_MTIMENSEC) pst->st_atime = ts.tv_sec; pst->st_atimensec = ts.tv_nsec; -#elif defined(HAVE_STAT_ST_ATIME_N) +#elif defined(HAVE_STRUCT_STAT_ST_MTIME_N) pst->st_atime = ts.tv_sec; pst->st_atime_n = ts.tv_nsec; -#elif defined(HAVE_STAT_ST_UATIME) +#elif defined(HAVE_STRUCT_STAT_ST_UMTIME) pst->st_atime = ts.tv_sec; pst->st_uatime = ts.tv_nsec / 1000; -#elif defined(HAVE_STAT_ST_ATIMESPEC) +#elif defined(HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC) pst->st_atimespec = ts; #else #error CONFIGURE_ERROR_IN_DETECTING_TIMESPEC_IN_STAT @@ -457,24 +457,24 @@ struct timespec get_mtimespec(const SMB_STRUCT_STAT *pst) ret.tv_nsec = 0; return ret; #else -#if defined(HAVE_STAT_ST_MTIM) +#if defined(HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC) return pst->st_mtim; -#elif defined(HAVE_STAT_ST_MTIMENSEC) +#elif defined(HAVE_STRUCT_STAT_ST_MTIMENSEC) struct timespec ret; ret.tv_sec = pst->st_mtime; ret.tv_nsec = pst->st_mtimensec; return ret; -#elif defined(HAVE_STAT_ST_MTIME_N) +#elif defined(HAVE_STRUCT_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_UMTIME) +#elif defined(HAVE_STRUCT_STAT_ST_UMTIME) struct timespec ret; ret.tv_sec = pst->st_mtime; ret.tv_nsec = pst->st_umtime * 1000; return ret; -#elif defined(HAVE_STAT_ST_MTIMESPEC) +#elif defined(HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC) return pst->st_mtimespec; #else #error CONFIGURE_ERROR_IN_DETECTING_TIMESPEC_IN_STAT @@ -488,18 +488,18 @@ void set_mtimespec(SMB_STRUCT_STAT *pst, struct timespec ts) /* Old system - no ns timestamp. */ pst->st_mtime = ts.tv_sec; #else -#if defined(HAVE_STAT_ST_MTIM) +#if defined(HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC) pst->st_mtim = ts; -#elif defined(HAVE_STAT_ST_MTIMENSEC) +#elif defined(HAVE_STRUCT_STAT_ST_MTIMENSEC) pst->st_mtime = ts.tv_sec; pst->st_mtimensec = ts.tv_nsec; -#elif defined(HAVE_STAT_ST_MTIME_N) +#elif defined(HAVE_STRUCT_STAT_ST_MTIME_N) pst->st_mtime = ts.tv_sec; pst->st_mtime_n = ts.tv_nsec; -#elif defined(HAVE_STAT_ST_UMTIME) +#elif defined(HAVE_STRUCT_STAT_ST_UMTIME) pst->st_mtime = ts.tv_sec; pst->st_umtime = ts.tv_nsec / 1000; -#elif defined(HAVE_STAT_ST_MTIMESPEC) +#elif defined(HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC) pst->st_mtimespec = ts; #else #error CONFIGURE_ERROR_IN_DETECTING_TIMESPEC_IN_STAT @@ -517,24 +517,24 @@ struct timespec get_ctimespec(const SMB_STRUCT_STAT *pst) ret.tv_nsec = 0; return ret; #else -#if defined(HAVE_STAT_ST_CTIM) +#if defined(HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC) return pst->st_ctim; -#elif defined(HAVE_STAT_ST_CTIMENSEC) +#elif defined(HAVE_STRUCT_STAT_ST_MTIMENSEC) struct timespec ret; ret.tv_sec = pst->st_ctime; ret.tv_nsec = pst->st_ctimensec; return ret; -#elif defined(HAVE_STAT_ST_CTIME_N) +#elif defined(HAVE_STRUCT_STAT_ST_MTIME_N) struct timespec ret; ret.tv_sec = pst->st_ctime; ret.tv_nsec = pst->st_ctime_n; return ret; -#elif defined(HAVE_STAT_ST_UCTIME) +#elif defined(HAVE_STRUCT_STAT_ST_UMTIME) struct timespec ret; ret.tv_sec = pst->st_ctime; ret.tv_nsec = pst->st_uctime * 1000; return ret; -#elif defined(HAVE_STAT_ST_CTIMESPEC) +#elif defined(HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC) return pst->st_ctimespec; #else #error CONFIGURE_ERROR_IN_DETECTING_TIMESPEC_IN_STAT @@ -548,18 +548,18 @@ void set_ctimespec(SMB_STRUCT_STAT *pst, struct timespec ts) /* Old system - no ns timestamp. */ pst->st_ctime = ts.tv_sec; #else -#if defined(HAVE_STAT_ST_CTIM) +#if defined(HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC) pst->st_ctim = ts; -#elif defined(HAVE_STAT_ST_CTIMENSEC) +#elif defined(HAVE_STRUCT_STAT_ST_MTIMENSEC) pst->st_ctime = ts.tv_sec; pst->st_ctimensec = ts.tv_nsec; -#elif defined(HAVE_STAT_ST_CTIME_N) +#elif defined(HAVE_STRUCT_STAT_ST_MTIME_N) pst->st_ctime = ts.tv_sec; pst->st_ctime_n = ts.tv_nsec; -#elif defined(HAVE_STAT_ST_UCTIME) +#elif defined(HAVE_STRUCT_STAT_ST_UMTIME) pst->st_ctime = ts.tv_sec; pst->st_uctime = ts.tv_nsec / 1000; -#elif defined(HAVE_STAT_ST_CTIMESPEC) +#elif defined(HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC) pst->st_ctimespec = ts; #else #error CONFIGURE_ERROR_IN_DETECTING_TIMESPEC_IN_STAT |