From 6bd8c2bc7b677fd0982da6498064b04a073f2537 Mon Sep 17 00:00:00 2001 From: Emil Velikov Date: Mon, 4 Nov 2024 14:32:39 +0000 Subject: [PATCH] libkmod: const struct index_mm as applicable The index_mm_{search,read,dump}* API does not mutate the index_mm struct. So let's annotate it as constant. Signed-off-by: Emil Velikov Link: https://github.com/kmod-project/kmod/pull/224 Signed-off-by: Lucas De Marchi --- libkmod/libkmod-index.c | 13 +++++++------ libkmod/libkmod-index.h | 6 +++--- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/libkmod/libkmod-index.c b/libkmod/libkmod-index.c index 0c007890..7909c774 100644 --- a/libkmod/libkmod-index.c +++ b/libkmod/libkmod-index.c @@ -613,7 +613,7 @@ struct index_mm_value { }; struct index_mm_node { - struct index_mm *idx; + const struct index_mm *idx; const char *prefix; /* mmap'ed value */ unsigned char first; unsigned char last; @@ -657,7 +657,8 @@ static inline void read_value_mm(const void **p, struct index_mm_value *v) } /* reads node into given node struct and returns its address on success or NULL on error. */ -static struct index_mm_node *index_mm_read_node(struct index_mm *idx, uint32_t offset, +static struct index_mm_node *index_mm_read_node(const struct index_mm *idx, + uint32_t offset, struct index_mm_node *node) { const void *p; @@ -797,7 +798,7 @@ void index_mm_close(struct index_mm *idx) free(idx); } -static struct index_mm_node *index_mm_readroot(struct index_mm *idx, +static struct index_mm_node *index_mm_readroot(const struct index_mm *idx, struct index_mm_node *root) { return index_mm_read_node(idx, idx->root_offset, root); @@ -854,7 +855,7 @@ static void index_mm_dump_node(struct index_mm_node *node, struct strbuf *buf, i strbuf_popchars(buf, pushed); } -void index_mm_dump(struct index_mm *idx, int fd, bool alias_prefix) +void index_mm_dump(const struct index_mm *idx, int fd, bool alias_prefix) { struct index_mm_node nbuf, *root; struct strbuf buf; @@ -911,7 +912,7 @@ static char *index_mm_search_node(struct index_mm_node *node, const char *key) * * Returns the value of the first match */ -char *index_mm_search(struct index_mm *idx, const char *key) +char *index_mm_search(const struct index_mm *idx, const char *key) { // FIXME: return value by reference instead of strdup struct index_mm_node nbuf, *root; @@ -1035,7 +1036,7 @@ static void index_mm_searchwild_node(struct index_mm_node *node, struct strbuf * * * Returns a list of all the values of matching keys. */ -struct index_value *index_mm_searchwild(struct index_mm *idx, const char *key) +struct index_value *index_mm_searchwild(const struct index_mm *idx, const char *key) { struct index_mm_node nbuf, *root; struct strbuf buf; diff --git a/libkmod/libkmod-index.h b/libkmod/libkmod-index.h index 1fbbd491..47c50d38 100644 --- a/libkmod/libkmod-index.h +++ b/libkmod/libkmod-index.h @@ -29,6 +29,6 @@ struct index_mm; int index_mm_open(const struct kmod_ctx *ctx, const char *filename, unsigned long long *stamp, struct index_mm **pidx); void index_mm_close(struct index_mm *index); -char *index_mm_search(struct index_mm *idx, const char *key); -struct index_value *index_mm_searchwild(struct index_mm *idx, const char *key); -void index_mm_dump(struct index_mm *idx, int fd, bool alias_prefix); +char *index_mm_search(const struct index_mm *idx, const char *key); +struct index_value *index_mm_searchwild(const struct index_mm *idx, const char *key); +void index_mm_dump(const struct index_mm *idx, int fd, bool alias_prefix); -- 2.47.2