aboutsummaryrefslogtreecommitdiff
path: root/project/dclib
diff options
context:
space:
mode:
authorWiimm <none>2020-10-01 15:32:28 +0200
committerWiimm <none>2020-10-01 15:32:28 +0200
commit18cf1faf0498a9821996cde8438e50403d9debd3 (patch)
treedc79d9cf4eee1dffa6f6afccc0bb14e2d674aa03 /project/dclib
parent29df9da71ba99a5f34ce01d95c033dbcfb745563 (diff)
SZS v2.20a.beta5: Test Mac build
Diffstat (limited to 'project/dclib')
-rw-r--r--project/dclib/dclib-file.c24
-rw-r--r--project/dclib/dclib-file.h115
2 files changed, 98 insertions, 41 deletions
diff --git a/project/dclib/dclib-file.c b/project/dclib/dclib-file.c
index 2cc8fa1..ef14011 100644
--- a/project/dclib/dclib-file.c
+++ b/project/dclib/dclib-file.c
@@ -254,12 +254,18 @@ FileAttrib_t * SetFileAttrib
memcpy(dest,src_fa,sizeof(*dest));
else if (src_stat)
{
- memset(dest,0,sizeof(*dest));
+ ZeroFileAttrib(dest);
if (S_ISREG(src_stat->st_mode))
{
+ #if HAVE_FILEATTRIB_NSEC
dest->atime = src_stat->st_atim;
dest->mtime = src_stat->st_mtim;
dest->ctime = src_stat->st_ctim;
+ #else
+ dest->atime.tv_sec = src_stat->st_atime;
+ dest->mtime.tv_sec = src_stat->st_mtime;
+ dest->ctime.tv_sec = src_stat->st_ctime;
+ #endif
dest->itime = CompareTimeSpec(&dest->mtime,&dest->ctime) > 0
? dest->mtime : dest->ctime;
dest->size = src_stat->st_size;
@@ -320,6 +326,7 @@ FileAttrib_t * MaxFileAttrib
{
if ( S_ISREG(src_stat->st_mode) )
{
+ #if HAVE_STATTIME_NSEC
if ( CompareTimeSpec(&dest->atime,&src_stat->st_atim) > 0 )
dest->atime = src_stat->st_atim;
@@ -333,6 +340,21 @@ FileAttrib_t * MaxFileAttrib
dest->itime = src_stat->st_mtim;
if ( CompareTimeSpec(&dest->itime,&src_stat->st_ctim) > 0 )
dest->itime = src_stat->st_ctim;
+ #else
+ if ( CompareTimeSpecTime(&dest->atime,src_stat->st_atime) > 0 )
+ dest->atime = src_stat->st_atim;
+
+ if ( CompareTimeSpecTime(&dest->mtime,src_stat->st_mtime) > 0 )
+ dest->mtime = src_stat->st_mtim;
+
+ if ( CompareTimeSpecTime(&dest->ctime,src_stat->st_ctime) > 0 )
+ dest->ctime = src_stat->st_ctim;
+
+ if ( CompareTimeSpecTime(&dest->itime,src_stat->st_mtime) > 0 )
+ dest->itime = src_stat->st_mtim;
+ if ( CompareTimeSpecTime(&dest->itime,src_stat->st_ctime) > 0 )
+ dest->itime = src_stat->st_ctim;
+ #endif
if ( dest->size < src_stat->st_size )
dest->size = src_stat->st_size;
diff --git a/project/dclib/dclib-file.h b/project/dclib/dclib-file.h
index 06f39b5..05e520e 100644
--- a/project/dclib/dclib-file.h
+++ b/project/dclib/dclib-file.h
@@ -124,6 +124,80 @@ ccp GetFileOpenMode
//
///////////////////////////////////////////////////////////////////////////////
+/////////////// nanoseconds: struct stat, struct timespec ///////////////
+///////////////////////////////////////////////////////////////////////////////
+
+#ifndef HAVE_STATTIME_NSEC
+ #if defined(st_atime) && defined(st_mtime) && defined(st_ctime) && !defined(__APPLE__)
+ #define HAVE_STATTIME_NSEC 1
+ #else
+ #define HAVE_STATTIME_NSEC 0
+ #endif
+#endif
+
+//-----------------------------------------------------------------------------
+
+#undef STATTIME_SEC
+#undef STATTIME_NSEC
+#if HAVE_STATTIME_NSEC
+ #define STATTIME_SEC(t) ((t).tv_sec)
+ #define STATTIME_NSEC(t) ((t).tv_nsec)
+#else
+ #define STATTIME_SEC(t) (t)
+ #define STATTIME_NSEC(t) 0
+#endif
+
+///////////////////////////////////////////////////////////////////////////////
+// struct timespec helpers
+
+extern const struct timespec null_timespec;
+
+// NULL pointers allowed
+int CompareTimeSpec0 ( const struct timespec *a, const struct timespec *b );
+
+// NULL pointers forbidden
+static inline int CompareTimeSpec
+ ( const struct timespec *a, const struct timespec *b )
+{
+ DASSERT(a);
+ DASSERT(b);
+ return a->tv_sec < b->tv_sec ? -1
+ : a->tv_sec > b->tv_sec ? 1
+ : a->tv_nsec < b->tv_nsec ? -1
+ : a->tv_nsec > b->tv_nsec;
+}
+
+// NULL pointers forbidden
+static inline int CompareTimeSpecVal
+ ( const struct timespec *a, const struct timeval *b )
+{
+ DASSERT(a);
+ DASSERT(b);
+ return a->tv_sec < b->tv_sec ? -1
+ : a->tv_sec > b->tv_sec ? 1
+ : a->tv_nsec < b->tv_usec*1000 ? -1
+ : a->tv_nsec > b->tv_usec*1000;
+}
+
+// NULL pointers forbidden
+static inline int CompareTimeSpecTime ( const struct timespec *a, const time_t tim )
+{
+ DASSERT(a);
+ DASSERT(b);
+ return a->tv_sec < tim ? -1
+ : a->tv_sec > tim ? 1
+ : a->tv_nsec > 0;
+}
+
+static inline bool IsTimeSpecNull ( const struct timespec *ts )
+{
+ return !ts
+ || ts->tv_nsec > 1000000000 // includes UTIME_NOW || UTIME_OMIT
+ || !ts->tv_nsec && !ts->tv_sec;
+}
+
+//
+///////////////////////////////////////////////////////////////////////////////
/////////////// struct FileAttrib_t ///////////////
///////////////////////////////////////////////////////////////////////////////
@@ -131,7 +205,7 @@ ccp GetFileOpenMode
#if defined(st_mtime) && !defined(__APPLE__)
#define HAVE_FILEATTRIB_NSEC 1
#else
- #define HAVE_FILEATTRIB_NSEC 0
+ #define HAVE_FILEATTRIB_NSEC 1
#endif
#endif
@@ -227,45 +301,6 @@ FileAttrib_t * NormalizeFileAttrib
FileAttrib_t * fa // valid attribute
);
-///////////////////////////////////////////////////////////////////////////////
-// struct timespec helpers
-
-extern const struct timespec null_timespec;
-
-// NULL pointers allowed
-int CompareTimeSpec0 ( const struct timespec *a, const struct timespec *b );
-
-// NULL pointers forbidden
-static inline int CompareTimeSpec
- ( const struct timespec *a, const struct timespec *b )
-{
- DASSERT(a);
- DASSERT(b);
- return a->tv_sec < b->tv_sec ? -1
- : a->tv_sec > b->tv_sec ? 1
- : a->tv_nsec < b->tv_nsec ? -1
- : a->tv_nsec > b->tv_nsec;
-}
-
-// NULL pointers forbidden
-static inline int CompareTimeSpecVal
- ( const struct timespec *a, const struct timeval *b )
-{
- DASSERT(a);
- DASSERT(b);
- return a->tv_sec < b->tv_sec ? -1
- : a->tv_sec > b->tv_sec ? 1
- : a->tv_nsec < b->tv_usec*1000 ? -1
- : a->tv_nsec > b->tv_usec*1000;
-}
-
-static inline bool IsTimeSpecNull ( const struct timespec *ts )
-{
- return !ts
- || ts->tv_nsec > 1000000000 // includes UTIME_NOW || UTIME_OMIT
- || !ts->tv_nsec && !ts->tv_sec;
-}
-
//
///////////////////////////////////////////////////////////////////////////////
/////////////// struct File_t ///////////////