diff options
author | Lennart Poettering <lennart@poettering.net> | 2009-08-26 01:41:34 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2009-08-26 01:41:34 +0200 |
commit | 827ae07c1ec73c8fe48dc4182726c38c3e9c992f (patch) | |
tree | ed18d2469babaefe1665e6132aa50fd9ec7d4863 /src/pulsecore | |
parent | 457b973ba69d1a417d438b8716389464eb62e049 (diff) |
macro: add PA_CLIP_SUB() for saturated subtraction
Diffstat (limited to 'src/pulsecore')
-rw-r--r-- | src/pulsecore/macro.h | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/src/pulsecore/macro.h b/src/pulsecore/macro.h index ce88c1b9..87684ad3 100644 --- a/src/pulsecore/macro.h +++ b/src/pulsecore/macro.h @@ -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; |