]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
lib/string/strdup/: xstrdup(): Reimplement xstrdup() in terms of exit_if_null()
authorAlejandro Colomar <alx@kernel.org>
Sun, 8 Dec 2024 11:04:11 +0000 (12:04 +0100)
committerIker Pedrosa <ikerpedrosam@gmail.com>
Mon, 27 Oct 2025 13:32:06 +0000 (14:32 +0100)
Signed-off-by: Alejandro Colomar <alx@kernel.org>
lib/string/strdup/xstrdup.c
lib/string/strdup/xstrdup.h

index 80ed58c4ee1bdedc0a0c2b11be0e9fe5125c4b07..3b83e1814edfaeaa4ee896e52859b527e1deae11 100644 (file)
@@ -1,7 +1,3 @@
-// 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
 
@@ -9,6 +5,3 @@
 #include "config.h"
 
 #include "string/strdup/xstrdup.h"
-
-
-extern inline char *xstrdup(const char *str);
index 29a442898a110165273d94507e9d4fce60478a86..9ba3f8359f5ba9b72ec959449ebdac5d7f0bda36 100644 (file)
@@ -1,8 +1,8 @@
 // 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-FileCopyrightText: 2008, Nicolas François
+// SPDX-FileCopyrightText: 2023-2025, Alejandro Colomar <alx@kernel.org>
 // SPDX-License-Identifier: BSD-3-Clause
 
 
 
 #include <string.h>
 
-#include "alloc/x/xmalloc.h"
-#include "attr.h"
+#include "exit_if_null.h"
 
 
-ATTR_MALLOC(free)
-inline char *xstrdup(const char *str);
-
-
-inline char *
-xstrdup(const char *str)
-{
-       return strcpy(XMALLOC(strlen(str) + 1, char), str);
-}
+// xstrdup - exit-on-error string duplicate
+#define xstrdup(s)  exit_if_null(strdup(s))
 
 
 #endif  // include guard