summaryrefslogtreecommitdiffstats
path: root/lib/utils_disk.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/utils_disk.c')
-rw-r--r--lib/utils_disk.c61
1 files changed, 61 insertions, 0 deletions
diff --git a/lib/utils_disk.c b/lib/utils_disk.c
index 582d3ea1..f5ac0b30 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
33void 34void
34np_add_name (struct name_list **list, const char *name) 35np_add_name (struct name_list **list, const char *name)
@@ -40,6 +41,42 @@ np_add_name (struct name_list **list, const char *name)
40 *list = new_entry; 41 *list = new_entry;
41} 42}
42 43
44/* @brief Initialises a new regex at the begin of list via regcomp(3)
45 *
46 * @details if the regex fails to compile the error code of regcomp(3) is returned
47 * and list is not modified, otherwise list is modified to point to the new
48 * element
49 * @param list Pointer to a linked list of regex_list elements
50 * @param regex the string containing the regex which should be inserted into the list
51 * @param clags the cflags parameter for regcomp(3)
52 */
53int
54np_add_regex (struct regex_list **list, const char *regex, int cflags)
55{
56 struct regex_list *new_entry = (struct regex_list *) malloc (sizeof *new_entry);
57
58 if (new_entry == NULL) {
59 die(STATE_UNKNOWN, _("Cannot allocate memory: %s"),
60 strerror(errno));
61 }
62
63 int regcomp_result = regcomp(&new_entry->regex, regex, cflags);
64
65 if (!regcomp_result) {
66 // regcomp succeeded
67 new_entry->next = *list;
68 *list = new_entry;
69
70 return 0;
71 } else {
72 // regcomp failed
73 free(new_entry);
74
75 return regcomp_result;
76 }
77
78}
79
43/* Initialises a new parameter at the end of list */ 80/* Initialises a new parameter at the end of list */
44struct parameter_list * 81struct parameter_list *
45np_add_parameter(struct parameter_list **list, const char *name) 82np_add_parameter(struct parameter_list **list, const char *name)
@@ -196,6 +233,30 @@ np_find_name (struct name_list *list, const char *name)
196 return FALSE; 233 return FALSE;
197} 234}
198 235
236/* Returns TRUE if name is in list */
237bool
238np_find_regmatch (struct regex_list *list, const char *name)
239{
240 int len;
241 regmatch_t m;
242
243 if (name == NULL) {
244 return false;
245 }
246
247 len = strlen(name);
248
249 for (; list; list = list->next) {
250 /* Emulate a full match as if surrounded with ^( )$
251 by checking whether the match spans the whole name */
252 if (!regexec(&list->regex, name, 1, &m, 0) && m.rm_so == 0 && m.rm_eo == len) {
253 return true;
254 }
255 }
256
257 return false;
258}
259
199int 260int
200np_seen_name(struct name_list *list, const char *name) 261np_seen_name(struct name_list *list, const char *name)
201{ 262{