From b7c8e3dbfa51017a40b0f7229a1e50074c0d9204 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 7 Aug 2018 09:21:45 +0200 Subject: [PATCH] shared: add NM_DIV_ROUND_UP() helper macro Inspired by ethtool's DIV_ROUND_UP() and systemd's DIV_ROUND_UP(). --- shared/nm-utils/nm-macros-internal.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/shared/nm-utils/nm-macros-internal.h b/shared/nm-utils/nm-macros-internal.h index d1391073eb..3d2520d131 100644 --- a/shared/nm-utils/nm-macros-internal.h +++ b/shared/nm-utils/nm-macros-internal.h @@ -1137,6 +1137,14 @@ nm_clear_g_cancellable (GCancellable **cancellable) && ((__x & (__x - (((typeof(__x)) 1)))) == ((typeof(__x)) 0))); \ }) +#define NM_DIV_ROUND_UP(x, y) \ + ({ \ + const typeof(x) _x = (x); \ + const typeof(y) _y = (y); \ + \ + (_x / _y + !!(_x % _y)); \ + }) + /*****************************************************************************/ #define NM_UTILS_LOOKUP_DEFAULT(v) return (v)