2610e7
From 5285f83b77df9e206f4904eba92c741eb42acc93 Mon Sep 17 00:00:00 2001
2610e7
From: Karel Zak <kzak@redhat.com>
2610e7
Date: Mon, 13 Dec 2021 13:19:18 +0100
2610e7
Subject: include/c: add cmp_timespec() and cmp_stat_mtime()
2610e7
2610e7
It's like timercmp() in libc, but for timespec and for stat.st_mtim
2610e7
(or stat.st_mtime for old struct stat versions).
2610e7
2610e7
Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=2180414
2610e7
Upstream: http://github.com/util-linux/util-linux/commit/0cfb8c5c3205a92ae81def278cdded63ea47094f
2610e7
Signed-off-by: Karel Zak <kzak@redhat.com>
2610e7
---
2610e7
 include/c.h | 18 ++++++++++++++++++
2610e7
 1 file changed, 18 insertions(+)
2610e7
2610e7
diff --git a/include/c.h b/include/c.h
2610e7
index 354b59e29..01f0fa507 100644
2610e7
--- a/include/c.h
2610e7
+++ b/include/c.h
2610e7
@@ -167,6 +167,24 @@
2610e7
 	_a == _b ? 0 : _a > _b ? 1 : -1; })
2610e7
 #endif
2610e7
 
2610e7
+
2610e7
+#ifndef cmp_timespec
2610e7
+# define cmp_timespec(a, b, CMP)		\
2610e7
+	(((a)->tv_sec == (b)->tv_sec)		\
2610e7
+	? ((a)->tv_nsec CMP (b)->tv_nsec)	\
2610e7
+	: ((a)->tv_sec CMP (b)->tv_sec))
2610e7
+#endif
2610e7
+
2610e7
+
2610e7
+#ifndef cmp_stat_mtime
2610e7
+# ifdef HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC
2610e7
+#  define cmp_stat_mtime(_a, _b, CMP)	cmp_timespec(&(_a)->st_mtim, &(_b)->st_mtim, CMP)
2610e7
+# else
2610e7
+#  define cmp_stat_mtime(_a, _b, CMP)	((_a)->st_mtime CMP (_b)->st_mtime)
2610e7
+# endif
2610e7
+#endif
2610e7
+
2610e7
+
2610e7
 #ifndef offsetof
2610e7
 #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
2610e7
 #endif
2610e7
-- 
2610e7
2.39.2
2610e7