]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
lib/string/strdup/xstrdup.[ch], lib/, src/: Move xstrdup() to its own file
authorAlejandro Colomar <alx@kernel.org>
Thu, 27 Jun 2024 12:16:16 +0000 (14:16 +0200)
committerSerge Hallyn <serge@hallyn.com>
Tue, 2 Jul 2024 02:40:11 +0000 (21:40 -0500)
Signed-off-by: Alejandro Colomar <alx@kernel.org>
26 files changed:
lib/Makefile.am
lib/alloc.c
lib/alloc.h
lib/env.c
lib/list.c
lib/motd.c
lib/obscure.c
lib/setupenv.c
lib/string/strdup/xstrdup.c [new file with mode: 0644]
lib/string/strdup/xstrdup.h [new file with mode: 0644]
lib/utmp.c
src/chage.c
src/chfn.c
src/chsh.c
src/gpasswd.c
src/groupmems.c
src/groupmod.c
src/login.c
src/newgrp.c
src/newusers.c
src/passwd.c
src/su.c
src/sulogin.c
src/useradd.c
src/userdel.c
src/usermod.c

index a713f98cb5df2b72eceb7e26d4aec67c56c14c44..231ed326e5fa2b15be601c92c4e36f505eb38e2a 100644 (file)
@@ -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 \
index 962f45a1d90eb165c9710caef1d72f1b00e74dc7..a9cbcaf0fdef9b0d98dc1255c976044167734afd 100644 (file)
@@ -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 <alx@kernel.org>
- *
- * 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 <alx@kernel.org>
+// 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 <config.h>
 
-#ident "$Id$"
-
 #include "alloc.h"
 
 #include <errno.h>
@@ -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 *
index 39405a56fc1d7f602f2b4ba0685fd268f07aae96..cf2e4b2e1f11b9091c2290c2a1245da10d341e4f 100644 (file)
@@ -15,7 +15,6 @@
 #include <stdlib.h>
 
 #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
index 8a59468a63cb6ababb8eba790b3740caf4ec7b5a..2debf35c2b26455e34d241e53fc3f2d334808bb3 100644 (file)
--- 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"
 
 
 /*
index 9fc660895e93f656d7cf117b8c462db427eb4527..8604cb63ed127239878a6891d24d5e54759dc829 100644 (file)
@@ -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
  *
index d1d5bf6e5ee6db8bc042efd2db5b2cb778a810ff..52712675f5d45309782d0e3a35bfd9f05fc3e048 100644 (file)
 
 #include <stdio.h>
 
-#include "alloc.h"
 #include "defines.h"
 #include "getdef.h"
 #include "prototypes.h"
+#include "string/strdup/xstrdup.h"
+
+
 /*
  * motd -- output the /etc/motd file
  *
index 32e8941ce833500cb3271c42f5fccc88b19a275d..136f26a67302583605c966fd29a287265f9b8511 100644 (file)
 #include <ctype.h>
 #include <stdio.h>
 
-#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"
index 8c58ac533dca8ad64edea2f5ab2aee8504f1e531..8eda5d58f3be45dc39104c74e72ed6e89f98422d 100644 (file)
 #include <stdio.h>
 #include <ctype.h>
 
-#include "alloc.h"
 #include "prototypes.h"
 #include "defines.h"
 #include <pwd.h>
 #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 (file)
index 0000000..00ec9db
--- /dev/null
@@ -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 <alx@kernel.org>
+// SPDX-License-Identifier: BSD-3-Clause
+
+
+#include <config.h>
+
+#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 (file)
index 0000000..1316418
--- /dev/null
@@ -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 <alx@kernel.org>
+// SPDX-License-Identifier: BSD-3-Clause
+
+
+#ifndef SHADOW_INCLUDE_LIB_STRING_STRDUP_XSTRDUP_H_
+#define SHADOW_INCLUDE_LIB_STRING_STRDUP_XSTRDUP_H_
+
+
+#include <config.h>
+
+#include <string.h>
+
+#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
index 40c32c18d6e81b9462c567ef2877e5a97bcf7022..ba80f7fd726f137beedf66a3a73a156016199e20 100644 (file)
@@ -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$"
index b8af89cfafe228141f23ea2b3544096b32f452e3..9b85b425a96427fbfd470b49bac664fd36ab3ecb 100644 (file)
@@ -26,7 +26,6 @@
 #endif                         /* ACCT_TOOLS_SETUID */
 #include <pwd.h>
 
-#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@*/
index e78037d3657e581cc26e7a5d4a175493ac411ff5..1872b2df4cb33a3d2c820bb807c8b6f45c39fc2d 100644 (file)
@@ -18,7 +18,6 @@
 #include <sys/types.h>
 #include <getopt.h>
 
-#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"
 
 
 /*
index c211c7a0fa3a287f84309f8536bd5b9e31a1d5b5..4e85678da120f55128d85d0a8463a57712a2b661 100644 (file)
@@ -17,7 +17,6 @@
 #include <stdio.h>
 #include <sys/types.h>
 
-#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"
index 0dc3a5f206830c669bb51c0c793788bd5a92447f..70d7547fe41f98cec860ccf1bcf5a75932d6bf65 100644 (file)
@@ -37,6 +37,7 @@
 #include "shadowlog.h"
 #include "string/sprintf/snprintf.h"
 #include "string/strcpy/strtcpy.h"
+#include "string/strdup/xstrdup.h"
 
 
 /*
index 0d0882db224b4befa6bd21867096601fc47bada4..444882cca8b79cbdea3a5a7a11434d8e303e6439 100644 (file)
@@ -27,6 +27,8 @@
 #include "sgroupio.h"
 #endif
 #include "shadowlog.h"
+#include "string/strdup/xstrdup.h"
+
 
 /* Exit Status Values */
 /*@-exitarg@*/
index e39b76b899f9e79e0389dac8d739666fe8adaea5..3f6d54eb6ff9df467f804147153dab0f917a0256 100644 (file)
@@ -41,6 +41,7 @@
 #include "shadowlog.h"
 #include "string/sprintf/stpeprintf.h"
 #include "string/strcpy/stpecpy.h"
+#include "string/strdup/xstrdup.h"
 
 
 /*
index f9f8606fb8647a38b0ddd4e0774de2e6a746f375..338c1a4336f8c4c95e7510055efe253e5752b2cc 100644 (file)
@@ -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"
 
 
index b9aec21d98290bf8943e451690a231ea19d4ac88..6542abf24fd2950400fa7642e63d20c1cf99c731 100644 (file)
@@ -26,6 +26,7 @@
 #include "exitcodes.h"
 #include "shadowlog.h"
 #include "string/sprintf/snprintf.h"
+#include "string/strdup/xstrdup.h"
 
 
 /*
index c28f8d891a3b08cfe10455d551b77483d36e1627..e5d20491ed29f753a71f197a24aba24be3423add 100644 (file)
@@ -53,6 +53,7 @@
 #include "chkname.h"
 #include "shadowlog.h"
 #include "string/sprintf/snprintf.h"
+#include "string/strdup/xstrdup.h"
 
 
 /*
index e22788f5c8e25f69ae6db39c3a3333ce284f1775..c2468d40d1d3fd5d06c1b62d343c858e1bad7419 100644 (file)
@@ -20,7 +20,6 @@
 #include <sys/types.h>
 #include <time.h>
 
-#include "alloc.h"
 #include "agetpass.h"
 #include "atoi/str2i.h"
 #include "defines.h"
 #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
  */
index cfc5ab1f215a96d224a637a49a5df3efe7c0ccd2..4e0d4100e617cc88db52265dbb4b6804660c1c50 100644 (file)
--- 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"
 
 
 /*
index 20971743260c96bc0aaaa2821e7e88858cb91b0e..6af471b5949b2c8d4eefe97817625d2ff1d6eb6f 100644 (file)
@@ -19,7 +19,6 @@
 #include <sys/types.h>
 
 #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"
 
 
 /*
index 52aed3ee089700ab96fd0f27c7d8c3ecafe262d9..4db0aa3a5610fbcf55a680ad54fb8a6f948d9deb 100644 (file)
@@ -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
index 38158d44332436043b506933b323b319b30e8a3f..ead696041bbfbcbebab88aa9f8208fce254f88c1 100644 (file)
@@ -20,7 +20,6 @@
 #include <sys/types.h>
 #include <unistd.h>
 
-#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"
 
 
 /*
index 1291814be33a86dc4641b8be36d196e82a339690..b688ee8edef5199ba3b0f10abfffe1ff635807a1 100644 (file)
@@ -62,6 +62,7 @@
 #endif
 #include "shadowlog.h"
 #include "string/sprintf/xasprintf.h"
+#include "string/strdup/xstrdup.h"
 #include "time/day_to_str.h"