From: Alejandro Colomar Date: Sun, 30 Jul 2023 12:05:10 +0000 (+0200) Subject: sizeof.h: Move sizeof()-related macros to their own header X-Git-Tag: 4.15.0-rc1~211 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=328958ca0168e3ce29509efeb190961d3affcc8f;p=thirdparty%2Fshadow.git sizeof.h: Move sizeof()-related macros to their own header Cc: Christian Göttsche Cc: Serge Hallyn Cc: Iker Pedrosa Signed-off-by: Alejandro Colomar --- diff --git a/lib/Makefile.am b/lib/Makefile.am index f58521515..3b56ce4cf 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 e85eaa8a4..9d6f1503d 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 a24a0c7d3..d517424cd 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 b4e459e67..d9f9cd523 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 000000000..b1a5daf11 --- /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 2cccdcd29..be8efa340 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 4b0f6882a..cd5bc5b72 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