1From cc0cd6f71f6ef96fca2d7b730a3f0f6722fec696 Mon Sep 17 00:00:00 2001
2From: Khem Raj <raj.khem@gmail.com>
3Date: Sat, 7 May 2022 12:15:22 -0700
4Subject: [PATCH] Define strndupa if it does not exist
5
6musl e.g. does not supply strndupa, unlike glibc
7
8Upstream-Status: Pending
9Signed-off-by: Khem Raj <raj.khem@gmail.com>
10
11---
12 etc/systemd/system-generators/zfs-mount-generator.c | 9 +++++++++
13 1 file changed, 9 insertions(+)
14
15diff --git a/etc/systemd/system-generators/zfs-mount-generator.c b/etc/systemd/system-generators/zfs-mount-generator.c
16index f4c6c26..255bee4 100644
17--- a/etc/systemd/system-generators/zfs-mount-generator.c
18+++ b/etc/systemd/system-generators/zfs-mount-generator.c
19@@ -193,6 +193,15 @@ fopenat(int dirfd, const char *pathname, int flags,
20 	return (fdopen(fd, stream_mode));
21 }
22
23+#ifndef strndupa
24+#define strndupa(s, n) \
25+       (__extension__ ({const char *__in = (s);                    \
26+                        size_t __len = strnlen (__in, (n)) + 1;    \
27+                        char *__out = (char *) alloca (__len);     \
28+                        __out[__len-1] = '\0';                     \
29+                        (char *) memcpy (__out, __in, __len-1);}))
30+#endif
31+
32 static int
33 line_worker(char *line, const char *cachefile)
34 {
35