From 881c1d63a19713bf62d9fbe3da0e15a4b4f9b375 Mon Sep 17 00:00:00 2001 From: Alejandro Colomar Date: Sun, 19 Feb 2023 20:40:16 +0100 Subject: [PATCH] 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 Use the new header for xstrdup() Signed-off-by: Alejandro Colomar --- lib/alloc.h | 13 +++++++++++++ lib/prototypes.h | 5 ----- libmisc/Makefile.am | 2 +- libmisc/{xmalloc.c => alloc.c} | 0 libmisc/copydir.c | 2 ++ libmisc/entry.c | 2 ++ libmisc/env.c | 2 ++ libmisc/motd.c | 4 +++- src/chage.c | 2 ++ src/chfn.c | 2 ++ src/chsh.c | 2 ++ 11 files changed, 29 insertions(+), 7 deletions(-) create mode 100644 lib/alloc.h rename libmisc/{xmalloc.c => alloc.c} (100%) diff --git a/lib/alloc.h b/lib/alloc.h new file mode 100644 index 00000000..9b1f8dc0 --- /dev/null +++ b/lib/alloc.h @@ -0,0 +1,13 @@ +#ifndef SHADOW_INCLUDE_LIB_MALLOC_H_ +#define SHADOW_INCLUDE_LIB_MALLOC_H_ + + +#include + +/* 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 diff --git a/lib/prototypes.h b/lib/prototypes.h index f4b4840d..400d5b97 100644 --- a/lib/prototypes.h +++ b/lib/prototypes.h @@ -477,11 +477,6 @@ extern int setutmp (struct utmp *ut); /* valid.c */ 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 */ extern /*@null@*/ /*@only@*/struct passwd *xgetpwnam (const char *); /* xgetpwuid.c */ diff --git a/libmisc/Makefile.am b/libmisc/Makefile.am index 655fd4bf..57f98e9e 100644 --- a/libmisc/Makefile.am +++ b/libmisc/Makefile.am @@ -10,6 +10,7 @@ libmisc_la_SOURCES = \ addgrps.c \ age.c \ agetpass.c \ + alloc.c \ audit_help.c \ basename.c \ bit.c \ @@ -78,7 +79,6 @@ libmisc_la_SOURCES = \ xgetgrnam.c \ xgetgrgid.c \ xgetspnam.c \ - xmalloc.c \ yesno.c if WITH_BTRFS diff --git a/libmisc/xmalloc.c b/libmisc/alloc.c similarity index 100% rename from libmisc/xmalloc.c rename to libmisc/alloc.c diff --git a/libmisc/copydir.c b/libmisc/copydir.c index 715d8f53..23fbd711 100644 --- a/libmisc/copydir.c +++ b/libmisc/copydir.c @@ -17,6 +17,8 @@ #include #include #include + +#include "alloc.h" #include "prototypes.h" #include "defines.h" #ifdef WITH_SELINUX diff --git a/libmisc/entry.c b/libmisc/entry.c index cc4029d0..88a06b24 100644 --- a/libmisc/entry.c +++ b/libmisc/entry.c @@ -13,6 +13,8 @@ #include #include + +#include "alloc.h" #include "prototypes.h" #include "defines.h" #include diff --git a/libmisc/env.c b/libmisc/env.c index eba365ae..640c96a5 100644 --- a/libmisc/env.c +++ b/libmisc/env.c @@ -15,6 +15,8 @@ #include #include #include + +#include "alloc.h" #include "prototypes.h" #include "defines.h" #include "shadowlog.h" diff --git a/libmisc/motd.c b/libmisc/motd.c index 7f7e523e..d1d5bf6e 100644 --- a/libmisc/motd.c +++ b/libmisc/motd.c @@ -12,9 +12,11 @@ #ident "$Id$" #include -#include "prototypes.h" + +#include "alloc.h" #include "defines.h" #include "getdef.h" +#include "prototypes.h" /* * motd -- output the /etc/motd file * diff --git a/src/chage.c b/src/chage.c index 997bab73..30d058ea 100644 --- a/src/chage.c +++ b/src/chage.c @@ -25,6 +25,8 @@ #endif /* USE_PAM */ #endif /* ACCT_TOOLS_SETUID */ #include + +#include "alloc.h" #include "prototypes.h" #include "defines.h" #include "pwio.h" diff --git a/src/chfn.c b/src/chfn.c index d56b329e..5018ab87 100644 --- a/src/chfn.c +++ b/src/chfn.c @@ -17,6 +17,8 @@ #include #include #include + +#include "alloc.h" #include "defines.h" #include "getdef.h" #include "nscd.h" diff --git a/src/chsh.c b/src/chsh.c index 64f53392..639ff630 100644 --- a/src/chsh.c +++ b/src/chsh.c @@ -16,6 +16,8 @@ #include #include #include + +#include "alloc.h" #include "defines.h" #include "getdef.h" #include "nscd.h"