From 3841fee822184d8df8d00d47b9143cdfcad49087 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 7 Jan 2020 16:24:33 +0100 Subject: [PATCH] path-util: introduce path_strv_contains() helper it's like strv_contains() but uses path_equal() rather than streq() to compare strings. --- src/basic/path-util.c | 10 ++++++++++ src/basic/path-util.h | 2 ++ 2 files changed, 12 insertions(+) diff --git a/src/basic/path-util.c b/src/basic/path-util.c index f1be8d09886..49a211a527d 100644 --- a/src/basic/path-util.c +++ b/src/basic/path-util.c @@ -1115,3 +1115,13 @@ bool empty_or_root(const char *root) { return root[strspn(root, "/")] == 0; } + +bool path_strv_contains(char **l, const char *path) { + char **i; + + STRV_FOREACH(i, l) + if (path_equal(*i, path)) + return true; + + return false; +} diff --git a/src/basic/path-util.h b/src/basic/path-util.h index 111d85d4455..3e8c12481be 100644 --- a/src/basic/path-util.h +++ b/src/basic/path-util.h @@ -181,3 +181,5 @@ bool empty_or_root(const char *root); static inline const char *empty_to_root(const char *path) { return isempty(path) ? "/" : path; } + +bool path_strv_contains(char **l, const char *path);