From: "Christian Göttsche" <cgzones@googlemail.com>
To: selinux@vger.kernel.org
Subject: [PATCH 2/2] libsepol: mark immutable common helper parameter const
Date: Thu, 31 Mar 2022 16:46:10 +0200 [thread overview]
Message-ID: <20220331144610.31056-2-cgzones@googlemail.com> (raw)
In-Reply-To: <20220331144610.31056-1-cgzones@googlemail.com>
Make it more obvious which parameters are read-only and not being
modified and allow callers to pass const pointers.
Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
---
libsepol/src/kernel_to_common.c | 16 ++++++++--------
libsepol/src/kernel_to_common.h | 16 ++++++++--------
2 files changed, 16 insertions(+), 16 deletions(-)
diff --git a/libsepol/src/kernel_to_common.c b/libsepol/src/kernel_to_common.c
index 972499ab..775703a9 100644
--- a/libsepol/src/kernel_to_common.c
+++ b/libsepol/src/kernel_to_common.c
@@ -267,12 +267,12 @@ void strs_sort(struct strs *strs)
qsort(strs->list, strs->num, sizeof(char *), strs_cmp);
}
-unsigned strs_num_items(struct strs *strs)
+unsigned strs_num_items(const struct strs *strs)
{
return strs->num;
}
-size_t strs_len_items(struct strs *strs)
+size_t strs_len_items(const struct strs *strs)
{
unsigned i;
size_t len = 0;
@@ -285,7 +285,7 @@ size_t strs_len_items(struct strs *strs)
return len;
}
-char *strs_to_str(struct strs *strs)
+char *strs_to_str(const struct strs *strs)
{
char *str = NULL;
size_t len = 0;
@@ -327,7 +327,7 @@ exit:
return str;
}
-void strs_write_each(struct strs *strs, FILE *out)
+void strs_write_each(const struct strs *strs, FILE *out)
{
unsigned i;
@@ -339,7 +339,7 @@ void strs_write_each(struct strs *strs, FILE *out)
}
}
-void strs_write_each_indented(struct strs *strs, FILE *out, int indent)
+void strs_write_each_indented(const struct strs *strs, FILE *out, int indent)
{
unsigned i;
@@ -360,7 +360,7 @@ int hashtab_ordered_to_strs(char *key, void *data, void *args)
return strs_add_at_index(strs, key, datum->value-1);
}
-int ebitmap_to_strs(struct ebitmap *map, struct strs *strs, char **val_to_name)
+int ebitmap_to_strs(const struct ebitmap *map, struct strs *strs, char **val_to_name)
{
struct ebitmap_node *node;
uint32_t i;
@@ -379,7 +379,7 @@ int ebitmap_to_strs(struct ebitmap *map, struct strs *strs, char **val_to_name)
return 0;
}
-char *ebitmap_to_str(struct ebitmap *map, char **val_to_name, int sort)
+char *ebitmap_to_str(const struct ebitmap *map, char **val_to_name, int sort)
{
struct strs *strs;
char *str = NULL;
@@ -427,7 +427,7 @@ char *strs_stack_pop(struct strs *stack)
return strs_remove_last(stack);
}
-int strs_stack_empty(struct strs *stack)
+int strs_stack_empty(const struct strs *stack)
{
return strs_num_items(stack) == 0;
}
diff --git a/libsepol/src/kernel_to_common.h b/libsepol/src/kernel_to_common.h
index e9932d30..159c4289 100644
--- a/libsepol/src/kernel_to_common.h
+++ b/libsepol/src/kernel_to_common.h
@@ -102,19 +102,19 @@ char *strs_remove_last(struct strs *strs);
int strs_add_at_index(struct strs *strs, char *s, size_t index);
char *strs_read_at_index(struct strs *strs, size_t index);
void strs_sort(struct strs *strs);
-unsigned strs_num_items(struct strs *strs);
-size_t strs_len_items(struct strs *strs);
-char *strs_to_str(struct strs *strs);
-void strs_write_each(struct strs *strs, FILE *out);
-void strs_write_each_indented(struct strs *strs, FILE *out, int indent);
+unsigned strs_num_items(const struct strs *strs);
+size_t strs_len_items(const struct strs *strs);
+char *strs_to_str(const struct strs *strs);
+void strs_write_each(const struct strs *strs, FILE *out);
+void strs_write_each_indented(const struct strs *strs, FILE *out, int indent);
int hashtab_ordered_to_strs(char *key, void *data, void *args);
-int ebitmap_to_strs(struct ebitmap *map, struct strs *strs, char **val_to_name);
-char *ebitmap_to_str(struct ebitmap *map, char **val_to_name, int sort);
+int ebitmap_to_strs(const struct ebitmap *map, struct strs *strs, char **val_to_name);
+char *ebitmap_to_str(const struct ebitmap *map, char **val_to_name, int sort);
int strs_stack_init(struct strs **stack);
void strs_stack_destroy(struct strs **stack);
int strs_stack_push(struct strs *stack, char *s);
char *strs_stack_pop(struct strs *stack);
-int strs_stack_empty(struct strs *stack);
+int strs_stack_empty(const struct strs *stack);
int sort_ocontexts(struct policydb *pdb);
--
2.35.1
next prev parent reply other threads:[~2022-03-31 14:46 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-31 14:46 [PATCH 1/2] libsepol: mark immutable mls and context parameter const Christian Göttsche
2022-03-31 14:46 ` Christian Göttsche [this message]
2022-04-01 17:27 ` James Carter
2022-04-06 9:27 ` Petr Lautrbach
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220331144610.31056-2-cgzones@googlemail.com \
--to=cgzones@googlemail.com \
--cc=selinux@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.