From: Alejandro Colomar Date: Thu, 27 Jun 2024 12:16:16 +0000 (+0200) Subject: lib/string/strdup/xstrdup.[ch], lib/, src/: Move xstrdup() to its own file X-Git-Tag: 4.17.0-rc1~178 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=29f4f03defae72c94097a9efa02a79212730947e;p=thirdparty%2Fshadow.git lib/string/strdup/xstrdup.[ch], lib/, src/: Move xstrdup() to its own file Signed-off-by: Alejandro Colomar --- diff --git a/lib/Makefile.am b/lib/Makefile.am index a713f98cb..231ed326e 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -160,6 +160,8 @@ libshadow_la_SOURCES = \ string/strcpy/strtcpy.h \ string/strdup/strndupa.c \ string/strdup/strndupa.h \ + string/strdup/xstrdup.c \ + string/strdup/xstrdup.h \ string/strdup/xstrndup.c \ string/strdup/xstrndup.h \ string/strftime.c \ diff --git a/lib/alloc.c b/lib/alloc.c index 962f45a1d..a9cbcaf0f 100644 --- a/lib/alloc.c +++ b/lib/alloc.c @@ -1,12 +1,9 @@ -/* - * SPDX-FileCopyrightText: 1990 - 1994, Julianne Frances Haugh - * SPDX-FileCopyrightText: 1996 - 1998, Marek Michałkiewicz - * SPDX-FileCopyrightText: 2003 - 2006, Tomasz Kłoczko - * SPDX-FileCopyrightText: 2008 , Nicolas François - * SPDX-FileCopyrightText: 2023 , Alejandro Colomar - * - * SPDX-License-Identifier: BSD-3-Clause - */ +// SPDX-FileCopyrightText: 1990-1994, Julianne Frances Haugh +// SPDX-FileCopyrightText: 1996-1998, Marek Michałkiewicz +// SPDX-FileCopyrightText: 2003-2006, Tomasz Kłoczko +// SPDX-FileCopyrightText: 2008 , Nicolas François +// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar +// SPDX-License-Identifier: BSD-3-Clause /* Replacements for malloc and strdup with error checking. Too trivial to be worth copyrighting :-). I did that because a lot of code used @@ -19,8 +16,6 @@ #include -#ident "$Id$" - #include "alloc.h" #include @@ -36,7 +31,6 @@ extern inline void *xmalloc(size_t size); extern inline void *xmallocarray(size_t nmemb, size_t size); extern inline void *mallocarray(size_t nmemb, size_t size); extern inline void *reallocarrayf(void *p, size_t nmemb, size_t size); -extern inline char *xstrdup(const char *str); void * diff --git a/lib/alloc.h b/lib/alloc.h index 39405a56f..cf2e4b2e1 100644 --- a/lib/alloc.h +++ b/lib/alloc.h @@ -15,7 +15,6 @@ #include #include "attr.h" -#include "defines.h" #define CALLOC(n, type) ((type *) calloc(n, sizeof(type))) @@ -47,8 +46,6 @@ ATTR_MALLOC(free) inline void *mallocarray(size_t nmemb, size_t size); ATTR_MALLOC(free) inline void *reallocarrayf(void *p, size_t nmemb, size_t size); -ATTR_MALLOC(free) -inline char *xstrdup(const char *str); ATTR_MALLOC(free) void *xcalloc(size_t nmemb, size_t size); @@ -91,11 +88,4 @@ reallocarrayf(void *p, size_t nmemb, size_t size) } -inline char * -xstrdup(const char *str) -{ - return strcpy(XMALLOC(strlen(str) + 1, char), str); -} - - #endif // include guard diff --git a/lib/env.c b/lib/env.c index 8a59468a6..2debf35c2 100644 --- a/lib/env.c +++ b/lib/env.c @@ -22,6 +22,7 @@ #include "shadowlog.h" #include "string/sprintf/snprintf.h" #include "string/sprintf/xasprintf.h" +#include "string/strdup/xstrdup.h" /* diff --git a/lib/list.c b/lib/list.c index 9fc660895..8604cb63e 100644 --- a/lib/list.c +++ b/lib/list.c @@ -15,6 +15,9 @@ #include "alloc.h" #include "prototypes.h" #include "defines.h" +#include "string/strdup/xstrdup.h" + + /* * add_list - add a member to a list of group members * diff --git a/lib/motd.c b/lib/motd.c index d1d5bf6e5..52712675f 100644 --- a/lib/motd.c +++ b/lib/motd.c @@ -13,10 +13,12 @@ #include -#include "alloc.h" #include "defines.h" #include "getdef.h" #include "prototypes.h" +#include "string/strdup/xstrdup.h" + + /* * motd -- output the /etc/motd file * diff --git a/lib/obscure.c b/lib/obscure.c index 32e8941ce..136f26a67 100644 --- a/lib/obscure.c +++ b/lib/obscure.c @@ -15,13 +15,14 @@ #include #include -#include "alloc.h" #include "attr.h" #include "memzero.h" #include "prototypes.h" #include "defines.h" #include "getdef.h" #include "string/sprintf/xasprintf.h" +#include "string/strdup/xstrdup.h" + #if WITH_LIBBSD == 0 #include "freezero.h" diff --git a/lib/setupenv.c b/lib/setupenv.c index 8c58ac533..8eda5d58f 100644 --- a/lib/setupenv.c +++ b/lib/setupenv.c @@ -21,13 +21,13 @@ #include #include -#include "alloc.h" #include "prototypes.h" #include "defines.h" #include #include "getdef.h" #include "shadowlog.h" #include "string/sprintf/xasprintf.h" +#include "string/strdup/xstrdup.h" #ifndef USE_PAM diff --git a/lib/string/strdup/xstrdup.c b/lib/string/strdup/xstrdup.c new file mode 100644 index 000000000..00ec9db3f --- /dev/null +++ b/lib/string/strdup/xstrdup.c @@ -0,0 +1,14 @@ +// SPDX-FileCopyrightText: 1990-1994, Julianne Frances Haugh +// SPDX-FileCopyrightText: 1996-1998, Marek Michałkiewicz +// SPDX-FileCopyrightText: 2003-2006, Tomasz Kłoczko +// SPDX-FileCopyrightText: 2008 , Nicolas François +// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar +// SPDX-License-Identifier: BSD-3-Clause + + +#include + +#include "string/strdup/xstrdup.h" + + +extern inline char *xstrdup(const char *str); diff --git a/lib/string/strdup/xstrdup.h b/lib/string/strdup/xstrdup.h new file mode 100644 index 000000000..13164182c --- /dev/null +++ b/lib/string/strdup/xstrdup.h @@ -0,0 +1,32 @@ +// SPDX-FileCopyrightText: 1990-1994, Julianne Frances Haugh +// SPDX-FileCopyrightText: 1996-1998, Marek Michałkiewicz +// SPDX-FileCopyrightText: 2003-2006, Tomasz Kłoczko +// SPDX-FileCopyrightText: 2008 , Nicolas François +// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar +// SPDX-License-Identifier: BSD-3-Clause + + +#ifndef SHADOW_INCLUDE_LIB_STRING_STRDUP_XSTRDUP_H_ +#define SHADOW_INCLUDE_LIB_STRING_STRDUP_XSTRDUP_H_ + + +#include + +#include + +#include "alloc.h" +#include "attr.h" + + +ATTR_MALLOC(free) +inline char *xstrdup(const char *str); + + +inline char * +xstrdup(const char *str) +{ + return strcpy(XMALLOC(strlen(str) + 1, char), str); +} + + +#endif // include guard diff --git a/lib/utmp.c b/lib/utmp.c index 40c32c18d..ba80f7fd7 100644 --- a/lib/utmp.c +++ b/lib/utmp.c @@ -26,6 +26,7 @@ #include "sizeof.h" #include "string/strcpy/strncpy.h" #include "string/strcpy/strtcpy.h" +#include "string/strdup/xstrdup.h" #include "string/strdup/xstrndup.h" #ident "$Id$" diff --git a/src/chage.c b/src/chage.c index b8af89cfa..9b85b425a 100644 --- a/src/chage.c +++ b/src/chage.c @@ -26,7 +26,6 @@ #endif /* ACCT_TOOLS_SETUID */ #include -#include "alloc.h" #include "atoi/str2i.h" #include "defines.h" #include "memzero.h" @@ -36,6 +35,7 @@ #include "shadowlog.h" #include "string/sprintf/snprintf.h" #include "string/strcpy/strtcpy.h" +#include "string/strdup/xstrdup.h" #include "string/strftime.h" #include "time/day_to_str.h" /*@-exitarg@*/ diff --git a/src/chfn.c b/src/chfn.c index e78037d36..1872b2df4 100644 --- a/src/chfn.c +++ b/src/chfn.c @@ -18,7 +18,6 @@ #include #include -#include "alloc.h" #include "defines.h" #include "getdef.h" #include "nscd.h" @@ -34,6 +33,7 @@ #include "shadowlog.h" #include "string/sprintf/snprintf.h" #include "string/strcpy/strtcpy.h" +#include "string/strdup/xstrdup.h" /* diff --git a/src/chsh.c b/src/chsh.c index c211c7a0f..4e85678da 100644 --- a/src/chsh.c +++ b/src/chsh.c @@ -17,7 +17,6 @@ #include #include -#include "alloc.h" #include "defines.h" #include "getdef.h" #include "nscd.h" @@ -32,6 +31,7 @@ #include "exitcodes.h" #include "shadowlog.h" #include "string/strcpy/strtcpy.h" +#include "string/strdup/xstrdup.h" #ifndef SHELLS_FILE #define SHELLS_FILE "/etc/shells" diff --git a/src/gpasswd.c b/src/gpasswd.c index 0dc3a5f20..70d7547fe 100644 --- a/src/gpasswd.c +++ b/src/gpasswd.c @@ -37,6 +37,7 @@ #include "shadowlog.h" #include "string/sprintf/snprintf.h" #include "string/strcpy/strtcpy.h" +#include "string/strdup/xstrdup.h" /* diff --git a/src/groupmems.c b/src/groupmems.c index 0d0882db2..444882cca 100644 --- a/src/groupmems.c +++ b/src/groupmems.c @@ -27,6 +27,8 @@ #include "sgroupio.h" #endif #include "shadowlog.h" +#include "string/strdup/xstrdup.h" + /* Exit Status Values */ /*@-exitarg@*/ diff --git a/src/groupmod.c b/src/groupmod.c index e39b76b89..3f6d54eb6 100644 --- a/src/groupmod.c +++ b/src/groupmod.c @@ -41,6 +41,7 @@ #include "shadowlog.h" #include "string/sprintf/stpeprintf.h" #include "string/strcpy/stpecpy.h" +#include "string/strdup/xstrdup.h" /* diff --git a/src/login.c b/src/login.c index f9f8606fb..338c1a433 100644 --- a/src/login.c +++ b/src/login.c @@ -40,6 +40,7 @@ #include "shadowlog.h" #include "string/sprintf/snprintf.h" #include "string/strcpy/strtcpy.h" +#include "string/strdup/xstrdup.h" #include "string/strftime.h" diff --git a/src/newgrp.c b/src/newgrp.c index b9aec21d9..6542abf24 100644 --- a/src/newgrp.c +++ b/src/newgrp.c @@ -26,6 +26,7 @@ #include "exitcodes.h" #include "shadowlog.h" #include "string/sprintf/snprintf.h" +#include "string/strdup/xstrdup.h" /* diff --git a/src/newusers.c b/src/newusers.c index c28f8d891..e5d20491e 100644 --- a/src/newusers.c +++ b/src/newusers.c @@ -53,6 +53,7 @@ #include "chkname.h" #include "shadowlog.h" #include "string/sprintf/snprintf.h" +#include "string/strdup/xstrdup.h" /* diff --git a/src/passwd.c b/src/passwd.c index e22788f5c..c2468d40d 100644 --- a/src/passwd.c +++ b/src/passwd.c @@ -20,7 +20,6 @@ #include #include -#include "alloc.h" #include "agetpass.h" #include "atoi/str2i.h" #include "defines.h" @@ -35,10 +34,10 @@ #include "shadowlog.h" #include "string/sprintf/xasprintf.h" #include "string/strcpy/strtcpy.h" +#include "string/strdup/xstrdup.h" #include "time/day_to_str.h" - /* * exit status values */ diff --git a/src/su.c b/src/su.c index cfc5ab1f2..4e0d4100e 100644 --- a/src/su.c +++ b/src/su.c @@ -62,6 +62,7 @@ #include "string/sprintf/snprintf.h" #include "string/sprintf/xasprintf.h" #include "string/strcpy/strtcpy.h" +#include "string/strdup/xstrdup.h" /* diff --git a/src/sulogin.c b/src/sulogin.c index 209717432..6af471b59 100644 --- a/src/sulogin.c +++ b/src/sulogin.c @@ -19,7 +19,6 @@ #include #include "agetpass.h" -#include "alloc.h" #include "attr.h" #include "defines.h" #include "getdef.h" @@ -28,6 +27,7 @@ /*@-exitarg@*/ #include "exitcodes.h" #include "shadowlog.h" +#include "string/strdup/xstrdup.h" /* diff --git a/src/useradd.c b/src/useradd.c index 52aed3ee0..4db0aa3a5 100644 --- a/src/useradd.c +++ b/src/useradd.c @@ -67,6 +67,7 @@ #include "shadowlog.h" #include "string/sprintf/snprintf.h" #include "string/sprintf/xasprintf.h" +#include "string/strdup/xstrdup.h" #ifndef SKEL_DIR diff --git a/src/userdel.c b/src/userdel.c index 38158d443..ead696041 100644 --- a/src/userdel.c +++ b/src/userdel.c @@ -20,7 +20,6 @@ #include #include -#include "alloc.h" #ifdef ACCT_TOOLS_SETUID #ifdef USE_PAM #include "pam_defs.h" @@ -53,6 +52,7 @@ #endif /* ENABLE_SUBIDS */ #include "shadowlog.h" #include "string/sprintf/xasprintf.h" +#include "string/strdup/xstrdup.h" /* diff --git a/src/usermod.c b/src/usermod.c index 1291814be..b688ee8ed 100644 --- a/src/usermod.c +++ b/src/usermod.c @@ -62,6 +62,7 @@ #endif #include "shadowlog.h" #include "string/sprintf/xasprintf.h" +#include "string/strdup/xstrdup.h" #include "time/day_to_str.h"