From eb164165f66e5785f5a5f8e0af650f4ff5d9ae95 Mon Sep 17 00:00:00 2001 From: Alejandro Colomar Date: Thu, 22 Dec 2022 13:51:20 +0100 Subject: [PATCH] Add NITEMS(arr) to get the number of elements of an array Signed-off-by: Alejandro Colomar --- lib/defines.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/defines.h b/lib/defines.h index b2185793..1a25e580 100644 --- a/lib/defines.h +++ b/lib/defines.h @@ -171,6 +171,8 @@ static inline void memzero(void *ptr, size_t size) #define SCALE DAY #endif +#define NITEMS(arr) (sizeof((arr)) / sizeof((arr)[0])) + /* Copy string pointed by B to array A with size checking. It was originally in lmain.c but is _very_ useful elsewhere. Some setuid root programs with very sloppy coding used to assume that BUFSIZ will always be enough... */