Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame^] | 1 | From 03fd19fc87573276e0d359260c8fe591f5f0216a Mon Sep 17 00:00:00 2001 |
| 2 | From: Chen Qi <Qi.Chen@windriver.com> |
| 3 | Date: Fri, 29 Jun 2018 16:34:50 +0800 |
| 4 | Subject: [PATCH 06/19] src/basic/missing.h: check for missing strndupa |
| 5 | |
| 6 | include missing.h for definition of strndupa |
| 7 | |
| 8 | Upstream-Status: Inappropriate [musl specific] |
| 9 | |
| 10 | Signed-off-by: Khem Raj <raj.khem@gmail.com> |
| 11 | Signed-off-by: Chen Qi <Qi.Chen@windriver.com> |
| 12 | --- |
| 13 | meson.build | 1 + |
| 14 | src/basic/missing.h | 11 +++++++++++ |
| 15 | src/basic/mkdir.c | 1 + |
| 16 | src/basic/pager.c | 1 + |
| 17 | src/basic/parse-util.c | 1 + |
| 18 | src/basic/procfs-util.c | 1 + |
| 19 | src/shared/uid-range.c | 1 + |
| 20 | 7 files changed, 17 insertions(+) |
| 21 | |
| 22 | diff --git a/meson.build b/meson.build |
| 23 | index 8c16bc979..a734a295c 100644 |
| 24 | --- a/meson.build |
| 25 | +++ b/meson.build |
| 26 | @@ -503,6 +503,7 @@ foreach ident : [ |
| 27 | #include <unistd.h>'''], |
| 28 | ['explicit_bzero' , '''#include <string.h>'''], |
| 29 | ['reallocarray', '''#include <malloc.h>'''], |
| 30 | + ['strndupa' , '''#include <string.h>'''], |
| 31 | ] |
| 32 | |
| 33 | have = cc.has_function(ident[0], prefix : ident[1], args : '-D_GNU_SOURCE') |
| 34 | diff --git a/src/basic/missing.h b/src/basic/missing.h |
| 35 | index 0e33abb9f..02397f1b6 100644 |
| 36 | --- a/src/basic/missing.h |
| 37 | +++ b/src/basic/missing.h |
| 38 | @@ -1184,6 +1184,17 @@ struct input_mask { |
| 39 | typedef int32_t key_serial_t; |
| 40 | #endif |
| 41 | |
| 42 | +#if ! HAVE_STRNDUPA |
| 43 | +#define strndupa(s, n) \ |
| 44 | + ({ \ |
| 45 | + const char *__old = (s); \ |
| 46 | + size_t __len = strnlen(__old, (n)); \ |
| 47 | + char *__new = (char *)alloca(__len + 1); \ |
| 48 | + __new[__len] = '\0'; \ |
| 49 | + (char *)memcpy(__new, __old, __len); \ |
| 50 | + }) |
| 51 | +#endif |
| 52 | + |
| 53 | #ifndef KEYCTL_JOIN_SESSION_KEYRING |
| 54 | #define KEYCTL_JOIN_SESSION_KEYRING 1 |
| 55 | #endif |
| 56 | diff --git a/src/basic/mkdir.c b/src/basic/mkdir.c |
| 57 | index 6ab1b4422..77c3e0863 100644 |
| 58 | --- a/src/basic/mkdir.c |
| 59 | +++ b/src/basic/mkdir.c |
| 60 | @@ -13,6 +13,7 @@ |
| 61 | #include "stat-util.h" |
| 62 | #include "stdio-util.h" |
| 63 | #include "user-util.h" |
| 64 | +#include "missing.h" |
| 65 | |
| 66 | int mkdir_safe_internal(const char *path, mode_t mode, uid_t uid, gid_t gid, MkdirFlags flags, mkdir_func_t _mkdir) { |
| 67 | struct stat st; |
| 68 | diff --git a/src/basic/pager.c b/src/basic/pager.c |
| 69 | index f24126111..8223bff02 100644 |
| 70 | --- a/src/basic/pager.c |
| 71 | +++ b/src/basic/pager.c |
| 72 | @@ -21,6 +21,7 @@ |
| 73 | #include "string-util.h" |
| 74 | #include "strv.h" |
| 75 | #include "terminal-util.h" |
| 76 | +#include "missing.h" |
| 77 | |
| 78 | static pid_t pager_pid = 0; |
| 79 | |
| 80 | diff --git a/src/basic/parse-util.c b/src/basic/parse-util.c |
| 81 | index 6becf8587..52576f536 100644 |
| 82 | --- a/src/basic/parse-util.c |
| 83 | +++ b/src/basic/parse-util.c |
| 84 | @@ -17,6 +17,7 @@ |
| 85 | #include "parse-util.h" |
| 86 | #include "process-util.h" |
| 87 | #include "string-util.h" |
| 88 | +#include "missing.h" |
| 89 | |
| 90 | int parse_boolean(const char *v) { |
| 91 | assert(v); |
| 92 | diff --git a/src/basic/procfs-util.c b/src/basic/procfs-util.c |
| 93 | index a159e344b..ebc427d6b 100644 |
| 94 | --- a/src/basic/procfs-util.c |
| 95 | +++ b/src/basic/procfs-util.c |
| 96 | @@ -11,6 +11,7 @@ |
| 97 | #include "procfs-util.h" |
| 98 | #include "stdio-util.h" |
| 99 | #include "string-util.h" |
| 100 | +#include "missing.h" |
| 101 | |
| 102 | int procfs_tasks_get_limit(uint64_t *ret) { |
| 103 | _cleanup_free_ char *value = NULL; |
| 104 | diff --git a/src/shared/uid-range.c b/src/shared/uid-range.c |
| 105 | index 434ce6ff4..37093ab7b 100644 |
| 106 | --- a/src/shared/uid-range.c |
| 107 | +++ b/src/shared/uid-range.c |
| 108 | @@ -8,6 +8,7 @@ |
| 109 | #include "macro.h" |
| 110 | #include "uid-range.h" |
| 111 | #include "user-util.h" |
| 112 | +#include "missing.h" |
| 113 | |
| 114 | static bool uid_range_intersect(UidRange *range, uid_t start, uid_t nr) { |
| 115 | assert(range); |
| 116 | -- |
| 117 | 2.11.0 |
| 118 | |