From 1f694195b4a6beef30bbbbffa5835a993be97a9c Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Wed, 23 Aug 2023 18:26:12 +0200 Subject: Introduce np_find_regmatch() --- lib/utils_disk.c | 25 +++++++++++++++++++++++++ lib/utils_disk.h | 1 + 2 files changed, 26 insertions(+) diff --git a/lib/utils_disk.c b/lib/utils_disk.c index ce02fdff..34401e21 100644 --- a/lib/utils_disk.c +++ b/lib/utils_disk.c @@ -29,6 +29,7 @@ #include "common.h" #include "utils_disk.h" #include "gl/fsusage.h" +#include void np_add_name (struct name_list **list, const char *name) @@ -207,6 +208,30 @@ np_find_name (struct name_list *list, const char *name) return FALSE; } +/* Returns TRUE if name is in list */ +bool +np_find_regmatch (struct regex_list *list, const char *name) +{ + int len; + regmatch_t m; + + if (name == NULL) { + return false; + } + + len = strlen(name); + + for (; list; list = list->next) { + /* Emulate a full match as if surrounded with ^( )$ + by checking whether the match spans the whole name */ + if (!regexec(&list->regex, name, 1, &m, 0) && m.rm_so == 0 && m.rm_eo == len) { + return true; + } + } + + return false; +} + int np_seen_name(struct name_list *list, const char *name) { diff --git a/lib/utils_disk.h b/lib/utils_disk.h index bda088f6..6b83ac74 100644 --- a/lib/utils_disk.h +++ b/lib/utils_disk.h @@ -42,6 +42,7 @@ void np_add_name (struct name_list **list, const char *name); int np_find_name (struct name_list *list, const char *name); int np_seen_name (struct name_list *list, const char *name); int np_add_regex (struct regex_list **list, const char *regex, int cflags); +bool np_find_regmatch (struct regex_list *list, const char *name); struct parameter_list *np_add_parameter(struct parameter_list **list, const char *name); struct parameter_list *np_find_parameter(struct parameter_list *list, const char *name); struct parameter_list *np_del_parameter(struct parameter_list *item, struct parameter_list *prev); -- cgit v1.2.3-74-g34f1