1
0
mirror of https://github.com/systemd/systemd.git synced 2025-01-09 01:18:19 +03:00

path-util: take char* const* for strv where appropriate

This commit is contained in:
Mike Yuan 2024-05-09 16:46:48 +08:00
parent 7b89efda6f
commit 63a0e57724
No known key found for this signature in database
GPG Key ID: 417471C0A40F58B3
2 changed files with 14 additions and 7 deletions

View File

@ -217,8 +217,10 @@ int path_make_relative_parent(const char *from_child, const char *to, char **ret
return path_make_relative(from, to, ret);
}
char* path_startswith_strv(const char *p, char **set) {
STRV_FOREACH(s, set) {
char* path_startswith_strv(const char *p, char * const *strv) {
assert(p);
STRV_FOREACH(s, strv) {
char *t;
t = path_startswith(p, *s);
@ -1368,7 +1370,9 @@ bool empty_or_root(const char *path) {
return path_equal(path, "/");
}
bool path_strv_contains(char **l, const char *path) {
bool path_strv_contains(char * const *l, const char *path) {
assert(path);
STRV_FOREACH(i, l)
if (path_equal(*i, path))
return true;
@ -1376,7 +1380,9 @@ bool path_strv_contains(char **l, const char *path) {
return false;
}
bool prefixed_path_strv_contains(char **l, const char *path) {
bool prefixed_path_strv_contains(char * const *l, const char *path) {
assert(path);
STRV_FOREACH(i, l) {
const char *j = *i;
@ -1384,6 +1390,7 @@ bool prefixed_path_strv_contains(char **l, const char *path) {
j++;
if (*j == '+')
j++;
if (path_equal(j, path))
return true;
}

View File

@ -108,7 +108,7 @@ static inline int path_simplify_alloc(const char *path, char **ret) {
/* Note: the search terminates on the first NULL item. */
#define PATH_IN_SET(p, ...) path_strv_contains(STRV_MAKE(__VA_ARGS__), p)
char* path_startswith_strv(const char *p, char **set);
char* path_startswith_strv(const char *p, char * const *strv);
#define PATH_STARTSWITH_SET(p, ...) path_startswith_strv(p, STRV_MAKE(__VA_ARGS__))
int path_strv_make_absolute_cwd(char **l);
@ -218,7 +218,7 @@ static inline const char* empty_to_root(const char *path) {
return isempty(path) ? "/" : path;
}
bool path_strv_contains(char **l, const char *path);
bool prefixed_path_strv_contains(char **l, const char *path);
bool path_strv_contains(char * const *l, const char *path);
bool prefixed_path_strv_contains(char * const *l, const char *path);
int path_glob_can_match(const char *pattern, const char *prefix, char **ret);