]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
lib/string/strdup/: XSTRNDUP(): Reimplement in terms of exit_if_null()
authorAlejandro Colomar <alx@kernel.org>
Wed, 1 Jan 2025 22:24:57 +0000 (23:24 +0100)
committerIker Pedrosa <ikerpedrosam@gmail.com>
Mon, 27 Oct 2025 13:32:06 +0000 (14:32 +0100)
This is much simpler.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
lib/string/strdup/xstrndup.h

index 8f41c02f94aeb4987c91a4dad34ac16a5d94dd55..d3279537aa02435b3636e10b899a935e8dd08da1 100644 (file)
@@ -1,4 +1,4 @@
-// SPDX-FileCopyrightText: 2024, Alejandro Colomar <alx@kernel.org>
+// SPDX-FileCopyrightText: 2024-2025, Alejandro Colomar <alx@kernel.org>
 // SPDX-License-Identifier: BSD-3-Clause
 
 
 
 #include <string.h>
 
-#include "alloc/x/xmalloc.h"
 #include "sizeof.h"
-#include "string/strcpy/strncat.h"
+#include "exit_if_null.h"
 
 
 // Similar to strndup(3), but ensure that 's' is an array, and exit on ENOMEM.
-#define XSTRNDUP(s)                                                           \
-(                                                                             \
-       STRNCAT(strcpy(XMALLOC(strnlen(s, countof(s)) + 1, char), ""), s)     \
-)
+#define XSTRNDUP(s)  exit_if_null(strndup(s, countof(s)))
 
 
 #endif  // include guard