]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
lib/string/strdup/strndupa.h: strndupa(3): Add macro
authorAlejandro Colomar <alx@kernel.org>
Sun, 19 Jan 2025 15:01:45 +0000 (16:01 +0100)
committerSerge Hallyn <serge@hallyn.com>
Tue, 27 May 2025 01:21:08 +0000 (20:21 -0500)
musl doesn't provide strndupa(3).

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

index cefc298205664ba66ccbe8b9942b682ea0758466..c8d53f30b2be10c9c9e96dba48f09431465fa795 100644 (file)
 #include "string/strcpy/strncat.h"
 
 
+// string n-bounded-read duplicate using-alloca(3)
+#ifndef  strndupa
+# define strndupa(s, n)  strncat(strcpy(alloca(n + 1), ""), s, n)
+#endif
+
+
 // Similar to strndupa(3), but ensure that 's' is an array.
 #define STRNDUPA(s)                                                           \
 (                                                                             \