diff options
Diffstat (limited to 'meta/recipes-kernel/kmod/kmod/0001-Use-portable-implementation-for-basename-API.patch')
-rw-r--r-- | meta/recipes-kernel/kmod/kmod/0001-Use-portable-implementation-for-basename-API.patch | 136 |
1 files changed, 136 insertions, 0 deletions
diff --git a/meta/recipes-kernel/kmod/kmod/0001-Use-portable-implementation-for-basename-API.patch b/meta/recipes-kernel/kmod/kmod/0001-Use-portable-implementation-for-basename-API.patch new file mode 100644 index 0000000000..6a7f9ded4f --- /dev/null +++ b/meta/recipes-kernel/kmod/kmod/0001-Use-portable-implementation-for-basename-API.patch | |||
@@ -0,0 +1,136 @@ | |||
1 | From 721ed6040c7aa47070faf6378c433089e178bd43 Mon Sep 17 00:00:00 2001 | ||
2 | From: Khem Raj <raj.khem@gmail.com> | ||
3 | Date: Sat, 9 Dec 2023 17:35:59 -0800 | ||
4 | Subject: [PATCH] Use portable implementation for basename API | ||
5 | |||
6 | musl has removed the non-prototype declaration of basename from | ||
7 | string.h [1] which now results in build errors with clang-17+ compiler | ||
8 | |||
9 | Implement GNU basename behavior using strchr which is portable across libcs | ||
10 | |||
11 | Fixes | ||
12 | ../git/tools/kmod.c:71:19: error: call to undeclared function 'basename'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration] | ||
13 | 71 | "Commands:\n", basename(argv[0])); | ||
14 | | ^ | ||
15 | |||
16 | [1] https://git.musl-libc.org/cgit/musl/commit/?id=725e17ed6dff4d0cd22487bb64470881e86a92e7 | ||
17 | |||
18 | Upstream-Status: Submitted [https://github.com/kmod-project/kmod/pull/32] | ||
19 | |||
20 | Suggested-by: Rich Felker | ||
21 | |||
22 | Signed-off-by: Khem Raj <raj.khem@gmail.com> | ||
23 | --- | ||
24 | libkmod/libkmod-config.c | 2 +- | ||
25 | shared/util.c | 4 ++-- | ||
26 | shared/util.h | 7 +++++++ | ||
27 | testsuite/testsuite.c | 2 +- | ||
28 | tools/depmod.c | 2 +- | ||
29 | tools/kmod.c | 4 ++-- | ||
30 | 6 files changed, 14 insertions(+), 7 deletions(-) | ||
31 | |||
32 | diff --git a/libkmod/libkmod-config.c b/libkmod/libkmod-config.c | ||
33 | index e83621b..8aa555a 100644 | ||
34 | --- a/libkmod/libkmod-config.c | ||
35 | +++ b/libkmod/libkmod-config.c | ||
36 | @@ -794,7 +794,7 @@ static int conf_files_insert_sorted(struct kmod_ctx *ctx, | ||
37 | bool is_single = false; | ||
38 | |||
39 | if (name == NULL) { | ||
40 | - name = basename(path); | ||
41 | + name = gnu_basename(path); | ||
42 | is_single = true; | ||
43 | } | ||
44 | |||
45 | diff --git a/shared/util.c b/shared/util.c | ||
46 | index e2bab83..0e16670 100644 | ||
47 | --- a/shared/util.c | ||
48 | +++ b/shared/util.c | ||
49 | @@ -172,9 +172,9 @@ char *modname_normalize(const char *modname, char buf[static PATH_MAX], size_t * | ||
50 | |||
51 | char *path_to_modname(const char *path, char buf[static PATH_MAX], size_t *len) | ||
52 | { | ||
53 | - char *modname; | ||
54 | + const char *modname; | ||
55 | |||
56 | - modname = basename(path); | ||
57 | + modname = gnu_basename(path); | ||
58 | if (modname == NULL || modname[0] == '\0') | ||
59 | return NULL; | ||
60 | |||
61 | diff --git a/shared/util.h b/shared/util.h | ||
62 | index c4a3916..073dc5a 100644 | ||
63 | --- a/shared/util.h | ||
64 | +++ b/shared/util.h | ||
65 | @@ -5,6 +5,7 @@ | ||
66 | #include <stdbool.h> | ||
67 | #include <stdlib.h> | ||
68 | #include <stdio.h> | ||
69 | +#include <string.h> | ||
70 | #include <sys/types.h> | ||
71 | #include <sys/stat.h> | ||
72 | #include <time.h> | ||
73 | @@ -76,6 +77,12 @@ do { \ | ||
74 | __p->__v = (val); \ | ||
75 | } while(0) | ||
76 | |||
77 | +static _always_inline_ const char *gnu_basename(const char *s) | ||
78 | +{ | ||
79 | + const char *p = strrchr(s, '/'); | ||
80 | + return p ? p+1 : s; | ||
81 | +} | ||
82 | + | ||
83 | static _always_inline_ unsigned int ALIGN_POWER2(unsigned int u) | ||
84 | { | ||
85 | return 1 << ((sizeof(u) * 8) - __builtin_clz(u - 1)); | ||
86 | diff --git a/testsuite/testsuite.c b/testsuite/testsuite.c | ||
87 | index 318343a..aafc987 100644 | ||
88 | --- a/testsuite/testsuite.c | ||
89 | +++ b/testsuite/testsuite.c | ||
90 | @@ -70,7 +70,7 @@ static void help(void) | ||
91 | |||
92 | printf("Usage:\n" | ||
93 | "\t%s [options] <test>\n" | ||
94 | - "Options:\n", basename(progname)); | ||
95 | + "Options:\n", gnu_basename(progname)); | ||
96 | |||
97 | for (itr = options, itr_short = options_short; | ||
98 | itr->name != NULL; itr++, itr_short++) | ||
99 | diff --git a/tools/depmod.c b/tools/depmod.c | ||
100 | index 43fc354..cfb15b1 100644 | ||
101 | --- a/tools/depmod.c | ||
102 | +++ b/tools/depmod.c | ||
103 | @@ -762,7 +762,7 @@ static int cfg_files_insert_sorted(struct cfg_file ***p_files, size_t *p_n_files | ||
104 | if (name != NULL) | ||
105 | namelen = strlen(name); | ||
106 | else { | ||
107 | - name = basename(dir); | ||
108 | + name = gnu_basename(dir); | ||
109 | namelen = strlen(name); | ||
110 | dirlen -= namelen + 1; | ||
111 | } | ||
112 | diff --git a/tools/kmod.c b/tools/kmod.c | ||
113 | index 55689c0..df91e5c 100644 | ||
114 | --- a/tools/kmod.c | ||
115 | +++ b/tools/kmod.c | ||
116 | @@ -68,7 +68,7 @@ static int kmod_help(int argc, char *argv[]) | ||
117 | "Options:\n" | ||
118 | "\t-V, --version show version\n" | ||
119 | "\t-h, --help show this help\n\n" | ||
120 | - "Commands:\n", basename(argv[0])); | ||
121 | + "Commands:\n", gnu_basename(argv[0])); | ||
122 | |||
123 | for (i = 0; i < ARRAY_SIZE(kmod_cmds); i++) { | ||
124 | if (kmod_cmds[i]->help != NULL) { | ||
125 | @@ -156,7 +156,7 @@ static int handle_kmod_compat_commands(int argc, char *argv[]) | ||
126 | const char *cmd; | ||
127 | size_t i; | ||
128 | |||
129 | - cmd = basename(argv[0]); | ||
130 | + cmd = gnu_basename(argv[0]); | ||
131 | |||
132 | for (i = 0; i < ARRAY_SIZE(kmod_compat_cmds); i++) { | ||
133 | if (streq(kmod_compat_cmds[i]->name, cmd)) | ||
134 | -- | ||
135 | 2.43.0 | ||
136 | |||