diff --git a/lib/string/strdup/strndupa.h b/lib/string/strdup/strndupa.h index cefc298205..80b8c3dcdb 100644 --- a/lib/string/strdup/strndupa.h +++ b/lib/string/strdup/strndupa.h @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: 2024, Alejandro Colomar +// SPDX-FileCopyrightText: 2024-2025, Alejandro Colomar // SPDX-License-Identifier: BSD-3-Clause @@ -12,14 +12,15 @@ #include #include "sizeof.h" -#include "string/strcpy/strncat.h" -// Similar to strndupa(3), but ensure that 's' is an array. -#define STRNDUPA(s) \ -( \ - STRNCAT(strcpy(alloca(strnlen(s, NITEMS(s)) + 1), ""), s) \ -) +// string n-bounded-read duplicate using-alloca(3) +#ifndef strndupa +# define strndupa(s, n) strncat(strcpy(alloca(n + 1), ""), s, n) +#endif + + +#define STRNDUPA(s) strndupa(s, NITEMS(s)) #endif // include guard