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>
This commit is contained in:
parent
d70f82acf3
commit
d4ef1c30e8
|
@ -15,6 +15,7 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <stdbool.h>
|
||||||
#include "modpost.h"
|
#include "modpost.h"
|
||||||
#include "../../include/generated/autoconf.h"
|
#include "../../include/generated/autoconf.h"
|
||||||
#include "../../include/linux/license.h"
|
#include "../../include/linux/license.h"
|
||||||
|
@ -78,6 +79,14 @@ PRINTF void merror(const char *fmt, ...)
|
||||||
va_end(arglist);
|
va_end(arglist);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline bool strends(const char *str, const char *postfix)
|
||||||
|
{
|
||||||
|
if (strlen(str) < strlen(postfix))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return strcmp(str + strlen(str) - strlen(postfix), postfix) == 0;
|
||||||
|
}
|
||||||
|
|
||||||
static int is_vmlinux(const char *modname)
|
static int is_vmlinux(const char *modname)
|
||||||
{
|
{
|
||||||
const char *myname;
|
const char *myname;
|
||||||
|
@ -113,22 +122,20 @@ static struct module *find_module(char *modname)
|
||||||
return mod;
|
return mod;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct module *new_module(char *modname)
|
static struct module *new_module(const char *modname)
|
||||||
{
|
{
|
||||||
struct module *mod;
|
struct module *mod;
|
||||||
char *p, *s;
|
char *p;
|
||||||
|
|
||||||
mod = NOFAIL(malloc(sizeof(*mod)));
|
mod = NOFAIL(malloc(sizeof(*mod)));
|
||||||
memset(mod, 0, sizeof(*mod));
|
memset(mod, 0, sizeof(*mod));
|
||||||
p = NOFAIL(strdup(modname));
|
p = NOFAIL(strdup(modname));
|
||||||
|
|
||||||
/* strip trailing .o */
|
/* strip trailing .o */
|
||||||
s = strrchr(p, '.');
|
if (strends(p, ".o")) {
|
||||||
if (s != NULL)
|
p[strlen(p) - 2] = '\0';
|
||||||
if (strcmp(s, ".o") == 0) {
|
mod->is_dot_o = 1;
|
||||||
*s = '\0';
|
}
|
||||||
mod->is_dot_o = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* add to list */
|
/* add to list */
|
||||||
mod->name = p;
|
mod->name = p;
|
||||||
|
|
Loading…
Reference in New Issue