From: Alejandro Colomar Date: Wed, 1 Jan 2025 22:24:57 +0000 (+0100) Subject: lib/string/strdup/: XSTRNDUP(): Reimplement in terms of exit_if_null() X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=b14d14a4055f87437c254db960254d89c7cd8f44;p=thirdparty%2Fshadow.git lib/string/strdup/: XSTRNDUP(): Reimplement in terms of exit_if_null() This is much simpler. Signed-off-by: Alejandro Colomar --- diff --git a/lib/string/strdup/xstrndup.h b/lib/string/strdup/xstrndup.h index 8f41c02f9..d3279537a 100644 --- a/lib/string/strdup/xstrndup.h +++ b/lib/string/strdup/xstrndup.h @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: 2024, Alejandro Colomar +// SPDX-FileCopyrightText: 2024-2025, Alejandro Colomar // SPDX-License-Identifier: BSD-3-Clause @@ -10,16 +10,12 @@ #include -#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