sizeof.h: Move sizeof()-related macros to their own header

Cc: Christian Göttsche <cgzones@googlemail.com>
Cc: Serge Hallyn <serge@hallyn.com>
Cc: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
This commit is contained in:
Alejandro Colomar
2023-07-30 14:05:10 +02:00
committed by Iker Pedrosa
parent 246edc0481
commit 328958ca01
7 changed files with 27 additions and 4 deletions

View File

@@ -131,6 +131,7 @@ libshadow_la_SOURCES = \
shadowlog_internal.h \
shadowmem.c \
shell.c \
sizeof.h \
spawn.c \
sssd.c \
sssd.h \

View File

@@ -20,6 +20,7 @@
#include "defines.h"
#include "prototypes.h"
#include "shadowlog.h"
#include "sizeof.h"
static uint32_t csrand_uniform32(uint32_t n);

View File

@@ -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... */

View File

@@ -21,6 +21,7 @@
#include <sys/capability.h>
#endif
#include "shadowlog.h"
#include "sizeof.h"
struct map_range *get_map_ranges(int ranges, int argc, char **argv)
{

21
lib/sizeof.h Normal file
View File

@@ -0,0 +1,21 @@
/*
* SPDX-FileCopyrightText: 2022-2023, Alejandro Colomar <alx@kernel.org>
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef SHADOW_INCLUDE_LIBMISC_SIZEOF_H_
#define SHADOW_INCLUDE_LIBMISC_SIZEOF_H_
#include <config.h>
#include <limits.h>
#define WIDTHOF(x) (sizeof(x) * CHAR_BIT)
#define NITEMS(arr) (sizeof((arr)) / sizeof((arr)[0]))
#define STRLEN(s) (NITEMS(s) - 1)
#endif // include guard

View File

@@ -23,6 +23,7 @@
#include <fcntl.h>
#include "alloc.h"
#include "sizeof.h"
#ident "$Id$"

View File

@@ -56,6 +56,8 @@
#include <netinet/in.h>
#include <arpa/inet.h> /* for inet_ntoa() */
#include "sizeof.h"
#if !defined(MAXHOSTNAMELEN) || (MAXHOSTNAMELEN < 64)
#undef MAXHOSTNAMELEN
#define MAXHOSTNAMELEN 256