diff --git a/lib/Makefile.am b/lib/Makefile.am index f5852151..3b56ce4c 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -131,6 +131,7 @@ libshadow_la_SOURCES = \ shadowlog_internal.h \ shadowmem.c \ shell.c \ + sizeof.h \ spawn.c \ sssd.c \ sssd.h \ diff --git a/lib/csrand.c b/lib/csrand.c index e85eaa8a..9d6f1503 100644 --- a/lib/csrand.c +++ b/lib/csrand.c @@ -20,6 +20,7 @@ #include "defines.h" #include "prototypes.h" #include "shadowlog.h" +#include "sizeof.h" static uint32_t csrand_uniform32(uint32_t n); diff --git a/lib/defines.h b/lib/defines.h index a24a0c7d..d517424c 100644 --- a/lib/defines.h +++ b/lib/defines.h @@ -155,10 +155,6 @@ #define SCALE DAY #endif -#define WIDTHOF(x) (sizeof(x) * CHAR_BIT) -#define NITEMS(arr) (sizeof((arr)) / sizeof((arr)[0])) -#define STRLEN(s) (NITEMS(s) - 1) - /* 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... */ diff --git a/lib/idmapping.c b/lib/idmapping.c index b4e459e6..d9f9cd52 100644 --- a/lib/idmapping.c +++ b/lib/idmapping.c @@ -21,6 +21,7 @@ #include #endif #include "shadowlog.h" +#include "sizeof.h" struct map_range *get_map_ranges(int ranges, int argc, char **argv) { diff --git a/lib/sizeof.h b/lib/sizeof.h new file mode 100644 index 00000000..b1a5daf1 --- /dev/null +++ b/lib/sizeof.h @@ -0,0 +1,21 @@ +/* + * SPDX-FileCopyrightText: 2022-2023, Alejandro Colomar + * SPDX-License-Identifier: BSD-3-Clause + */ + + +#ifndef SHADOW_INCLUDE_LIBMISC_SIZEOF_H_ +#define SHADOW_INCLUDE_LIBMISC_SIZEOF_H_ + + +#include + +#include + + +#define WIDTHOF(x) (sizeof(x) * CHAR_BIT) +#define NITEMS(arr) (sizeof((arr)) / sizeof((arr)[0])) +#define STRLEN(s) (NITEMS(s) - 1) + + +#endif // include guard diff --git a/lib/utmp.c b/lib/utmp.c index 2cccdcd2..be8efa34 100644 --- a/lib/utmp.c +++ b/lib/utmp.c @@ -23,6 +23,7 @@ #include #include "alloc.h" +#include "sizeof.h" #ident "$Id$" diff --git a/src/login_nopam.c b/src/login_nopam.c index 4b0f6882..cd5bc5b7 100644 --- a/src/login_nopam.c +++ b/src/login_nopam.c @@ -56,6 +56,8 @@ #include #include /* for inet_ntoa() */ +#include "sizeof.h" + #if !defined(MAXHOSTNAMELEN) || (MAXHOSTNAMELEN < 64) #undef MAXHOSTNAMELEN #define MAXHOSTNAMELEN 256