]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
Add WIDTHOF() to get the width in bits
authorAlejandro Colomar <alx@kernel.org>
Wed, 18 Jan 2023 11:38:18 +0000 (12:38 +0100)
committerSerge Hallyn <serge@hallyn.com>
Sat, 28 Jan 2023 03:48:37 +0000 (21:48 -0600)
It is common to use the expression 'sizeof(x) * CHAR_BIT' to mean the
width in bits of a type or object.  Now that there are _WIDTH macros for
some types, indicating the number of bits that they use, it makes sense
to wrap this calculation in a macro of a similar name.

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

index d3416f1193971a7c58f59ecbcb889603e5e5ae42..5ef11c021140c59816af8c7191bb0d8a9f66b4bc 100644 (file)
@@ -169,6 +169,7 @@ static inline void memzero(void *ptr, size_t size)
 #define SCALE DAY
 #endif
 
+#define WIDTHOF(x)   (sizeof(x) * CHAR_BIT)
 #define NITEMS(arr)  (sizeof((arr)) / sizeof((arr)[0]))
 
 /* Copy string pointed by B to array A with size checking.  It was originally