aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/mod
diff options
context:
space:
mode:
authorRusty Russell <rusty@rustcorp.com.au>2013-04-04 03:07:32 -0400
committerRusty Russell <rusty@rustcorp.com.au>2013-04-04 21:18:06 -0400
commitd4ef1c30e89ce8e7f1030501d74b6b812c3c179d (patch)
treeb7e45a75923cdf70362e1070fade384ade5344c1 /scripts/mod
parentd70f82acf32affa78ae4957caa0fb2a550d2c6ea (diff)
modpost: minor cleanup.
We want a strends() function next, so make one and use it appropriately, making new_module() arg const while we're at it. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Diffstat (limited to 'scripts/mod')
-rw-r--r--scripts/mod/modpost.c23
1 files changed, 15 insertions, 8 deletions
diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
index f6913db77627..f7a0392ad1ca 100644
--- a/scripts/mod/modpost.c
+++ b/scripts/mod/modpost.c
@@ -15,6 +15,7 @@
15#include <stdio.h> 15#include <stdio.h>
16#include <ctype.h> 16#include <ctype.h>
17#include <string.h> 17#include <string.h>
18#include <stdbool.h>
18#include "modpost.h" 19#include "modpost.h"
19#include "../../include/generated/autoconf.h" 20#include "../../include/generated/autoconf.h"
20#include "../../include/linux/license.h" 21#include "../../include/linux/license.h"
@@ -78,6 +79,14 @@ PRINTF void merror(const char *fmt, ...)
78 va_end(arglist); 79 va_end(arglist);
79} 80}
80 81
82static inline bool strends(const char *str, const char *postfix)
83{
84 if (strlen(str) < strlen(postfix))
85 return false;
86
87 return strcmp(str + strlen(str) - strlen(postfix), postfix) == 0;
88}
89
81static int is_vmlinux(const char *modname) 90static int is_vmlinux(const char *modname)
82{ 91{
83 const char *myname; 92 const char *myname;
@@ -113,22 +122,20 @@ static struct module *find_module(char *modname)
113 return mod; 122 return mod;
114} 123}
115 124
116static struct module *new_module(char *modname) 125static struct module *new_module(const char *modname)
117{ 126{
118 struct module *mod; 127 struct module *mod;
119 char *p, *s; 128 char *p;
120 129
121 mod = NOFAIL(malloc(sizeof(*mod))); 130 mod = NOFAIL(malloc(sizeof(*mod)));
122 memset(mod, 0, sizeof(*mod)); 131 memset(mod, 0, sizeof(*mod));
123 p = NOFAIL(strdup(modname)); 132 p = NOFAIL(strdup(modname));
124 133
125 /* strip trailing .o */ 134 /* strip trailing .o */
126 s = strrchr(p, '.'); 135 if (strends(p, ".o")) {
127 if (s != NULL) 136 p[strlen(p) - 2] = '\0';
128 if (strcmp(s, ".o") == 0) { 137 mod->is_dot_o = 1;
129 *s = '\0'; 138 }
130 mod->is_dot_o = 1;
131 }
132 139
133 /* add to list */ 140 /* add to list */
134 mod->name = p; 141 mod->name = p;