summaryrefslogtreecommitdiffstats
path: root/meta/recipes-core/systemd/systemd/0002-src-basic-missing.h-check-for-missing-strndupa.patch
blob: 94c136b0d9413509bf476b715863b28a334fa7da (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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
From 585abd891a56409915314304101cac26b42c076b Mon Sep 17 00:00:00 2001
From: Emil Renner Berthing <systemd@esmil.dk>
Date: Mon, 23 Oct 2017 10:45:46 -0700
Subject: [PATCH 02/12] src/basic/missing.h: check for missing strndupa

include missing.h  for definition of strndupa

Signed-off-by: Khem Raj <raj.khem@gmail.com>
---
Upstream-Status: Pending

 configure.ac           |  1 +
 src/basic/missing.h    | 11 +++++++++++
 src/basic/mkdir.c      |  1 +
 src/basic/parse-util.c |  1 +
 src/shared/pager.c     |  1 +
 src/shared/uid-range.c |  1 +
 6 files changed, 16 insertions(+)

diff --git a/configure.ac b/configure.ac
index efcdc6c16..cd035a971 100644
--- a/configure.ac
+++ b/configure.ac
@@ -329,6 +329,7 @@ AC_CHECK_DECLS([
         pivot_root,
         name_to_handle_at,
         setns,
+        strndupa,
         renameat2,
         kcmp,
         keyctl,
diff --git a/src/basic/missing.h b/src/basic/missing.h
index 04912bf52..8009888ad 100644
--- a/src/basic/missing.h
+++ b/src/basic/missing.h
@@ -1104,6 +1104,17 @@ typedef int32_t key_serial_t;
 #define KEYCTL_DESCRIBE 6
 #endif
 
+#if !HAVE_DECL_STRNDUPA
+#define strndupa(s, n) \
+  ({ \
+    const char *__old = (s); \
+    size_t __len = strnlen(__old, (n)); \
+    char *__new = (char *)alloca(__len + 1); \
+    __new[__len] = '\0'; \
+    (char *)memcpy(__new, __old, __len); \
+  })
+#endif
+
 #ifndef KEYCTL_READ
 #define KEYCTL_READ 11
 #endif
diff --git a/src/basic/mkdir.c b/src/basic/mkdir.c
index 6b1a98402..d1388df48 100644
--- a/src/basic/mkdir.c
+++ b/src/basic/mkdir.c
@@ -28,6 +28,7 @@
 #include "path-util.h"
 #include "stat-util.h"
 #include "user-util.h"
+#include "missing.h"
 
 int mkdir_safe_internal(const char *path, mode_t mode, uid_t uid, gid_t gid, mkdir_func_t _mkdir) {
         struct stat st;
diff --git a/src/basic/parse-util.c b/src/basic/parse-util.c
index 4532f222c..7a30a0e06 100644
--- a/src/basic/parse-util.c
+++ b/src/basic/parse-util.c
@@ -30,6 +30,7 @@
 #include "parse-util.h"
 #include "process-util.h"
 #include "string-util.h"
+#include "missing.h"
 
 int parse_boolean(const char *v) {
         assert(v);
diff --git a/src/shared/pager.c b/src/shared/pager.c
index 4d7b02c63..854efc0c9 100644
--- a/src/shared/pager.c
+++ b/src/shared/pager.c
@@ -38,6 +38,7 @@
 #include "string-util.h"
 #include "strv.h"
 #include "terminal-util.h"
+#include "missing.h"
 
 static pid_t pager_pid = 0;
 
diff --git a/src/shared/uid-range.c b/src/shared/uid-range.c
index b6ec47439..91ce9fb7f 100644
--- a/src/shared/uid-range.c
+++ b/src/shared/uid-range.c
@@ -24,6 +24,7 @@
 #include "macro.h"
 #include "uid-range.h"
 #include "user-util.h"
+#include "missing.h"
 
 static bool uid_range_intersect(UidRange *range, uid_t start, uid_t nr) {
         assert(range);
-- 
2.14.2