From b14d14a4055f87437c254db960254d89c7cd8f44 Mon Sep 17 00:00:00 2001 From: Alejandro Colomar Date: Wed, 1 Jan 2025 23:24:57 +0100 Subject: [PATCH] lib/string/strdup/: XSTRNDUP(): Reimplement in terms of exit_if_null() This is much simpler. Signed-off-by: Alejandro Colomar --- lib/string/strdup/xstrndup.h | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) 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 -- 2.47.3