]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
macro: update DIV_ROUND_UP() so that it can be called nested
authorLennart Poettering <lennart@poettering.net>
Fri, 9 Nov 2018 10:37:21 +0000 (11:37 +0100)
committerLennart Poettering <lennart@poettering.net>
Fri, 30 Nov 2018 15:46:10 +0000 (16:46 +0100)
src/basic/macro.h

index 0a258cc614a146a99b23ba7baa64a65d518f0328..f54f13e4fe4fde320273049e718c9918dfbd2c5f 100644 (file)
@@ -246,11 +246,12 @@ static inline unsigned long ALIGN_POWER2(unsigned long u) {
  * computation should be possible in the given type. Therefore, we use
  * [x / y + !!(x % y)]. Note that on "Real CPUs" a division returns both the
  * quotient and the remainder, so both should be equally fast. */
-#define DIV_ROUND_UP(_x, _y)                                            \
+#define DIV_ROUND_UP(x, y) __DIV_ROUND_UP(UNIQ, (x), UNIQ, (y))
+#define __DIV_ROUND_UP(xq, x, yq, y)                                    \
         ({                                                              \
-                const typeof(_x) __x = (_x);                            \
-                const typeof(_y) __y = (_y);                            \
-                (__x / __y + !!(__x % __y));                            \
+                const typeof(x) UNIQ_T(X, xq) = (x);                    \
+                const typeof(y) UNIQ_T(Y, yq) = (y);                    \
+                (UNIQ_T(X, xq) / UNIQ_T(Y, yq) + !!(UNIQ_T(X, xq) % UNIQ_T(Y, yq))); \
         })
 
 #ifdef __COVERITY__