set: introduce set_fnmatch()

This commit is contained in:
Yu Watanabe
2022-04-27 16:32:15 +09:00
parent cf393c5f44
commit d25d4f189c
3 changed files with 73 additions and 0 deletions
+25
View File
@@ -1,6 +1,7 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#include <errno.h>
#include <fnmatch.h>
#include <pthread.h>
#include <stdint.h>
#include <stdlib.h>
@@ -2070,3 +2071,27 @@ bool set_equal(Set *a, Set *b) {
return true;
}
static bool set_fnmatch_one(Set *patterns, const char *needle) {
const char *p;
assert(needle);
SET_FOREACH(p, patterns)
if (fnmatch(p, needle, 0) == 0)
return true;
return false;
}
bool set_fnmatch(Set *include_patterns, Set *exclude_patterns, const char *needle) {
assert(needle);
if (set_fnmatch_one(exclude_patterns, needle))
return false;
if (set_isempty(include_patterns))
return true;
return set_fnmatch_one(include_patterns, needle);
}
+2
View File
@@ -153,3 +153,5 @@ DEFINE_TRIVIAL_CLEANUP_FUNC(Set*, set_free_free);
int set_strjoin(Set *s, const char *separator, bool wrap_with_separator, char **ret);
bool set_equal(Set *a, Set *b);
bool set_fnmatch(Set *include_patterns, Set *exclude_patterns, const char *needle);