]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
lib/sizeof.h: Define SIZEOF_ARRAY() in terms of countof()
authorAlejandro Colomar <alx@kernel.org>
Wed, 21 May 2025 11:58:05 +0000 (13:58 +0200)
committerSerge Hallyn <serge@hallyn.com>
Tue, 3 Jun 2025 14:34:55 +0000 (09:34 -0500)
This will allow us to eventually get rid of must_be_array(), once
we make sure countof() is safe.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
lib/sizeof.h

index fc1a2dd3e0b036e127554661ef1b922faed0818c..af7cf4b9bd3bee39864874d203afad0a880e0058 100644 (file)
 #define ssizeof(x)           ((ssize_t) sizeof(x))
 #define memberof(T, member)  ((T){}.member)
 #define WIDTHOF(x)           (sizeof(x) * CHAR_BIT)
-#define SIZEOF_ARRAY(a)      (sizeof(a) + must_be_array(a))
 
 #if !defined(countof)
-# define countof(a)          (SIZEOF_ARRAY((a)) / sizeof((a)[0]))
+# define countof(a)          (sizeof(a) / sizeof((a)[0]) + must_be_array(a))
 #endif
 
+#define SIZEOF_ARRAY(a)      (countof(a) * sizeof((a)[0]))
 #define STRLEN(s)            (countof("" s "") - 1)