aboutsummaryrefslogtreecommitdiffstats
path: root/meta-filesystems/recipes-filesystems/zfs/zfs/0001-Define-strndupa-if-it-does-not-exist.patch
blob: 8bb8b9479a1423d2d894a30997a7f452366e4a32 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
From 54883e714b7fd1e7f4ce47eb1fc09adff35d561e Mon Sep 17 00:00:00 2001
From: Khem Raj <raj.khem@gmail.com>
Date: Sat, 7 May 2022 12:15:22 -0700
Subject: [PATCH] Define strndupa if it does not exist

musl e.g. does not supply strndupa, unlike glibc

Upstream-Status: Pending
Signed-off-by: Khem Raj <raj.khem@gmail.com>
---
 etc/systemd/system-generators/zfs-mount-generator.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/etc/systemd/system-generators/zfs-mount-generator.c b/etc/systemd/system-generators/zfs-mount-generator.c
index b806339..592d2f9 100644
--- a/etc/systemd/system-generators/zfs-mount-generator.c
+++ b/etc/systemd/system-generators/zfs-mount-generator.c
@@ -47,6 +47,15 @@
 #define	STRCMP ((int(*)(const void *, const void *))&strcmp)
 #define	PID_T_CMP ((int(*)(const void *, const void *))&pid_t_cmp)
 
+#ifndef strndupa
+#define strndupa(s, n) \
+       (__extension__ ({const char *__in = (s);                    \
+                        size_t __len = strnlen (__in, (n)) + 1;    \
+                        char *__out = (char *) alloca (__len);     \
+                        __out[__len-1] = '\0';                     \
+                        (char *) memcpy (__out, __in, __len-1);}))
+#endif
+
 static int
 pid_t_cmp(const pid_t *lhs, const pid_t *rhs)
 {
-- 
2.36.0