libmisc: Move xmalloc.c to alloc.c

We'll expand the contents in a following commit, so let's move the file
to a more generic name, have a dedicated header, and update includes.

Signed-off-by: Alejandro Colomar <alx@kernel.org>

Use the new header for xstrdup()

Signed-off-by: Alejandro Colomar <alx@kernel.org>
This commit is contained in:
Alejandro Colomar 2023-02-19 20:40:16 +01:00 committed by Serge Hallyn
parent a578617cc0
commit 881c1d63a1
11 changed files with 29 additions and 7 deletions

13
lib/alloc.h Normal file
View File

@ -0,0 +1,13 @@
#ifndef SHADOW_INCLUDE_LIB_MALLOC_H_
#define SHADOW_INCLUDE_LIB_MALLOC_H_
#include <stddef.h>
/* xmalloc.c */
extern /*@maynotreturn@*/ /*@only@*//*@out@*//*@notnull@*/void *xmalloc (size_t size)
/*@ensures MaxSet(result) == (size - 1); @*/;
extern /*@maynotreturn@*/ /*@only@*//*@notnull@*/char *xstrdup (const char *);
#endif // include guard

View File

@ -477,11 +477,6 @@ extern int setutmp (struct utmp *ut);
/* valid.c */ /* valid.c */
extern bool valid (const char *, const struct passwd *); extern bool valid (const char *, const struct passwd *);
/* xmalloc.c */
extern /*@maynotreturn@*/ /*@only@*//*@out@*//*@notnull@*/void *xmalloc (size_t size)
/*@ensures MaxSet(result) == (size - 1); @*/;
extern /*@maynotreturn@*/ /*@only@*//*@notnull@*/char *xstrdup (const char *);
/* xgetpwnam.c */ /* xgetpwnam.c */
extern /*@null@*/ /*@only@*/struct passwd *xgetpwnam (const char *); extern /*@null@*/ /*@only@*/struct passwd *xgetpwnam (const char *);
/* xgetpwuid.c */ /* xgetpwuid.c */

View File

@ -10,6 +10,7 @@ libmisc_la_SOURCES = \
addgrps.c \ addgrps.c \
age.c \ age.c \
agetpass.c \ agetpass.c \
alloc.c \
audit_help.c \ audit_help.c \
basename.c \ basename.c \
bit.c \ bit.c \
@ -78,7 +79,6 @@ libmisc_la_SOURCES = \
xgetgrnam.c \ xgetgrnam.c \
xgetgrgid.c \ xgetgrgid.c \
xgetspnam.c \ xgetspnam.c \
xmalloc.c \
yesno.c yesno.c
if WITH_BTRFS if WITH_BTRFS

View File

@ -17,6 +17,8 @@
#include <sys/time.h> #include <sys/time.h>
#include <fcntl.h> #include <fcntl.h>
#include <stdio.h> #include <stdio.h>
#include "alloc.h"
#include "prototypes.h" #include "prototypes.h"
#include "defines.h" #include "defines.h"
#ifdef WITH_SELINUX #ifdef WITH_SELINUX

View File

@ -13,6 +13,8 @@
#include <sys/types.h> #include <sys/types.h>
#include <stdio.h> #include <stdio.h>
#include "alloc.h"
#include "prototypes.h" #include "prototypes.h"
#include "defines.h" #include "defines.h"
#include <pwd.h> #include <pwd.h>

View File

@ -15,6 +15,8 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include "alloc.h"
#include "prototypes.h" #include "prototypes.h"
#include "defines.h" #include "defines.h"
#include "shadowlog.h" #include "shadowlog.h"

View File

@ -12,9 +12,11 @@
#ident "$Id$" #ident "$Id$"
#include <stdio.h> #include <stdio.h>
#include "prototypes.h"
#include "alloc.h"
#include "defines.h" #include "defines.h"
#include "getdef.h" #include "getdef.h"
#include "prototypes.h"
/* /*
* motd -- output the /etc/motd file * motd -- output the /etc/motd file
* *

View File

@ -25,6 +25,8 @@
#endif /* USE_PAM */ #endif /* USE_PAM */
#endif /* ACCT_TOOLS_SETUID */ #endif /* ACCT_TOOLS_SETUID */
#include <pwd.h> #include <pwd.h>
#include "alloc.h"
#include "prototypes.h" #include "prototypes.h"
#include "defines.h" #include "defines.h"
#include "pwio.h" #include "pwio.h"

View File

@ -17,6 +17,8 @@
#include <stdio.h> #include <stdio.h>
#include <sys/types.h> #include <sys/types.h>
#include <getopt.h> #include <getopt.h>
#include "alloc.h"
#include "defines.h" #include "defines.h"
#include "getdef.h" #include "getdef.h"
#include "nscd.h" #include "nscd.h"

View File

@ -16,6 +16,8 @@
#include <pwd.h> #include <pwd.h>
#include <stdio.h> #include <stdio.h>
#include <sys/types.h> #include <sys/types.h>
#include "alloc.h"
#include "defines.h" #include "defines.h"
#include "getdef.h" #include "getdef.h"
#include "nscd.h" #include "nscd.h"