]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
include/c: add cmp_timespec() and cmp_stat_mtime()
authorKarel Zak <kzak@redhat.com>
Mon, 13 Dec 2021 12:19:18 +0000 (13:19 +0100)
committerKarel Zak <kzak@redhat.com>
Mon, 13 Dec 2021 12:19:18 +0000 (13:19 +0100)
It's like timercmp() in libc, but for timespec and for stat.st_mtim
(or stat.st_mtime for old struct stat versions).

Signed-off-by: Karel Zak <kzak@redhat.com>
include/c.h

index ba799d8fd344e92fb47d1ef2190351652c77ca4c..db0c58b5099e1f7cd5e296a63b5264c75dfb0c04 100644 (file)
        _a == _b ? 0 : _a > _b ? 1 : -1; })
 #endif
 
+
+#ifndef cmp_timespec
+# define cmp_timespec(a, b, CMP)               \
+       (((a)->tv_sec == (b)->tv_sec)           \
+       ? ((a)->tv_nsec CMP (b)->tv_nsec)       \
+       : ((a)->tv_sec CMP (b)->tv_sec))
+#endif
+
+
+#ifndef cmp_stat_mtime
+# ifdef HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC
+#  define cmp_stat_mtime(_a, _b, CMP)  cmp_timespec(&(_a)->st_mtim, &(_b)->st_mtim, CMP)
+# else
+#  define cmp_stat_mtime(_a, _b, CMP)  ((_a)->st_mtime CMP (_b)->st_mtime)
+# endif
+#endif
+
+
 #ifndef offsetof
 #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
 #endif