Introduce the simple macro and use it to (better) illustrate the strbuf
size calculation.
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/451
Signed-off-by: Lucas De Marchi <demarchi@kernel.org>
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + _array_size_chk(arr))
+#define _ALIGN_MASK(x, _MASK) (((x) + (_MASK)) & ~(_MASK))
+#define ALIGN(x, B) _ALIGN_MASK(x, (typeof(x))(B) - 1)
+
#define XSTRINGIFY(x) #x
#define STRINGIFY(x) XSTRINGIFY(x)
#include <string.h>
#include <sys/param.h>
-#include "util.h"
+#include "macro.h"
#include "strbuf.h"
+#include "util.h"
#define BUF_STEP 128
n > SIZE_MAX - BUF_STEP)
return false;
- if (n % BUF_STEP)
- n = ((n / BUF_STEP) + 1) * BUF_STEP;
+ n = ALIGN(n, BUF_STEP);
return buf_realloc(buf, n);
}