chiark / gitweb /
util: generalize code that checks whether PIDs are alive or unwaited for
[elogind.git] / src / shared / macro.h
index 2b5b3fdfe0038e3c74e419441f7621f68aad9d29..dfbc20142f753172ee8708f5e5aa94eca27fa66b 100644 (file)
@@ -30,7 +30,6 @@
 #define _printf_(a,b) __attribute__ ((format (printf, a, b)))
 #define _alloc_(...) __attribute__ ((alloc_size(__VA_ARGS__)))
 #define _sentinel_ __attribute__ ((sentinel))
-#define _noreturn_ __attribute__((noreturn))
 #define _unused_ __attribute__ ((unused))
 #define _destructor_ __attribute__ ((destructor))
 #define _pure_ __attribute__ ((pure))
@@ -118,6 +117,13 @@ static inline size_t ALIGN_TO(size_t l, size_t ali) {
                         _a < _b ? _a : _b;      \
                 })
 
+#define LESS_BY(A,B)                            \
+        __extension__ ({                        \
+                        typeof(A) _A = (A);     \
+                        typeof(B) _B = (B);     \
+                        _A > _B ? _A - _B : 0;  \
+                })
+
 #ifndef CLAMP
 #define CLAMP(x, low, high)                                             \
         __extension__ ({                                                \
@@ -300,7 +306,8 @@ do {                                                                    \
                 _found;                                                 \
         })
 
-/* Define C11 thread_local attribute even on older compilers */
+/* Define C11 thread_local attribute even on older gcc compiler
+ * version */
 #ifndef thread_local
 /*
  * Don't break on glibc < 2.16 that doesn't define __STDC_NO_THREADS__
@@ -313,4 +320,14 @@ do {                                                                    \
 #endif
 #endif
 
+/* Define C11 noreturn without <stdnoreturn.h> and even on older gcc
+ * compiler versions */
+#ifndef noreturn
+#if __STDC_VERSION__ >= 201112L
+#define noreturn _Noreturn
+#else
+#define noreturn __attribute__((noreturn))
+#endif
+#endif
+
 #include "log.h"