diff options
author | Alexander A. Klimov <alexander.klimov@icinga.com> | 2023-08-23 18:26:12 +0200 |
---|---|---|
committer | Alexander A. Klimov <alexander.klimov@icinga.com> | 2023-09-28 13:20:24 +0200 |
commit | 1f694195b4a6beef30bbbbffa5835a993be97a9c (patch) | |
tree | 0a9add089b64d64a4a802e9ae2c371450ac6257b /lib | |
parent | d31a696cadb0bba0914d76aad0eb48c6e7962b8e (diff) | |
download | monitoring-plugins-1f694195b4a6beef30bbbbffa5835a993be97a9c.tar.gz |
Introduce np_find_regmatch()
Diffstat (limited to 'lib')
-rw-r--r-- | lib/utils_disk.c | 25 | ||||
-rw-r--r-- | lib/utils_disk.h | 1 |
2 files changed, 26 insertions, 0 deletions
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 @@ | |||
29 | #include "common.h" | 29 | #include "common.h" |
30 | #include "utils_disk.h" | 30 | #include "utils_disk.h" |
31 | #include "gl/fsusage.h" | 31 | #include "gl/fsusage.h" |
32 | #include <string.h> | ||
32 | 33 | ||
33 | void | 34 | void |
34 | np_add_name (struct name_list **list, const char *name) | 35 | np_add_name (struct name_list **list, const char *name) |
@@ -207,6 +208,30 @@ np_find_name (struct name_list *list, const char *name) | |||
207 | return FALSE; | 208 | return FALSE; |
208 | } | 209 | } |
209 | 210 | ||
211 | /* Returns TRUE if name is in list */ | ||
212 | bool | ||
213 | np_find_regmatch (struct regex_list *list, const char *name) | ||
214 | { | ||
215 | int len; | ||
216 | regmatch_t m; | ||
217 | |||
218 | if (name == NULL) { | ||
219 | return false; | ||
220 | } | ||
221 | |||
222 | len = strlen(name); | ||
223 | |||
224 | for (; list; list = list->next) { | ||
225 | /* Emulate a full match as if surrounded with ^( )$ | ||
226 | by checking whether the match spans the whole name */ | ||
227 | if (!regexec(&list->regex, name, 1, &m, 0) && m.rm_so == 0 && m.rm_eo == len) { | ||
228 | return true; | ||
229 | } | ||
230 | } | ||
231 | |||
232 | return false; | ||
233 | } | ||
234 | |||
210 | int | 235 | int |
211 | np_seen_name(struct name_list *list, const char *name) | 236 | np_seen_name(struct name_list *list, const char *name) |
212 | { | 237 | { |
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); | |||
42 | int np_find_name (struct name_list *list, const char *name); | 42 | int np_find_name (struct name_list *list, const char *name); |
43 | int np_seen_name (struct name_list *list, const char *name); | 43 | int np_seen_name (struct name_list *list, const char *name); |
44 | int np_add_regex (struct regex_list **list, const char *regex, int cflags); | 44 | int np_add_regex (struct regex_list **list, const char *regex, int cflags); |
45 | bool np_find_regmatch (struct regex_list *list, const char *name); | ||
45 | struct parameter_list *np_add_parameter(struct parameter_list **list, const char *name); | 46 | struct parameter_list *np_add_parameter(struct parameter_list **list, const char *name); |
46 | struct parameter_list *np_find_parameter(struct parameter_list *list, const char *name); | 47 | struct parameter_list *np_find_parameter(struct parameter_list *list, const char *name); |
47 | struct parameter_list *np_del_parameter(struct parameter_list *item, struct parameter_list *prev); | 48 | struct parameter_list *np_del_parameter(struct parameter_list *item, struct parameter_list *prev); |