]> code.delx.au - pulseaudio/commitdiff
macro: add PA_CLIP_SUB() for saturated subtraction
authorLennart Poettering <lennart@poettering.net>
Tue, 25 Aug 2009 23:41:34 +0000 (01:41 +0200)
committerLennart Poettering <lennart@poettering.net>
Tue, 25 Aug 2009 23:41:34 +0000 (01:41 +0200)
src/pulsecore/macro.h

index ce88c1b9d33871a78d1200bfb306d33c059aed31..87684ad3d3641cfafc2012b3574a7fab5951a61b 100644 (file)
@@ -157,6 +157,17 @@ static inline size_t PA_PAGE_ALIGN(size_t l) {
 #define PA_ROUND_DOWN(a, b) (((a) / (b)) * (b))
 #endif
 
+#ifdef __GNUC__
+#define PA_CLIP_SUB(a, b)                       \
+    __extension__ ({                            \
+            typeof(a) _a = (a);                 \
+            typeof(b) _b = (b);                 \
+            _a > _b ? _a - _b : 0;              \
+        })
+#else
+#define PA_CLIP_SUB(a, b) ((a) > (b) ? (a) - (b) : 0)
+#endif
+
 /* This type is not intended to be used in exported APIs! Use classic "int" there! */
 #ifdef HAVE_STD_BOOL
 typedef _Bool pa_bool_t;