kmod_module: use pointer instead of vector for its name
We still have name allocated just after the struct kmod_module, but
now we use a pointer instead of putting name as a vector in the end of
the structure.
The previous way has some problems, the worst is:
- it's not possible to swap the name with another value: this is
the real problem that this patch is solving. Later patches
will make name be swappable with alias, which is not possible
if name is a vector.
diff --git a/libkmod/libkmod-module.c b/libkmod/libkmod-module.c
index 9429f1d..0e71aea 100644
--- a/libkmod/libkmod-module.c
+++ b/libkmod/libkmod-module.c
@@ -45,6 +45,7 @@
*/
struct kmod_module {
struct kmod_ctx *ctx;
+ char *name;
char *path;
struct kmod_list *dep;
char *options;
@@ -58,7 +59,6 @@
bool install_commands : 1;
bool remove_commands : 1;
} init;
- char name[];
};
inline char *modname_normalize(const char *modname, char buf[NAME_MAX],
@@ -214,6 +214,7 @@
}
m->ctx = kmod_ref(ctx);
+ m->name = (char *)m + sizeof(*m);
memcpy(m->name, name_norm, namelen + 1);
m->refcount = 1;
@@ -275,6 +276,7 @@
return -errno;
m->ctx = kmod_ref(ctx);
+ m->name = (char *)m + sizeof(*m);
memcpy(m->name, name, namelen);
m->path = abspath;
m->refcount = 1;