diff options
| -rw-r--r-- | lib/utils_disk.c | 33 |
1 files changed, 29 insertions, 4 deletions
diff --git a/lib/utils_disk.c b/lib/utils_disk.c index 34401e21..884f0052 100644 --- a/lib/utils_disk.c +++ b/lib/utils_disk.c | |||
| @@ -41,15 +41,40 @@ np_add_name (struct name_list **list, const char *name) | |||
| 41 | *list = new_entry; | 41 | *list = new_entry; |
| 42 | } | 42 | } |
| 43 | 43 | ||
| 44 | /* Initialises a new regex at the begin of list via regcomp(3) */ | 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 | */ | ||
| 45 | int | 53 | int |
| 46 | np_add_regex (struct regex_list **list, const char *regex, int cflags) | 54 | np_add_regex (struct regex_list **list, const char *regex, int cflags) |
| 47 | { | 55 | { |
| 48 | struct regex_list *new_entry = (struct regex_list *) malloc (sizeof *new_entry); | 56 | struct regex_list *new_entry = (struct regex_list *) malloc (sizeof *new_entry); |
| 49 | new_entry->next = *list; | ||
| 50 | *list = new_entry; | ||
| 51 | 57 | ||
| 52 | return regcomp(&new_entry->regex, regex, cflags); | 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 succeded | ||
| 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 | |||
| 53 | } | 78 | } |
| 54 | 79 | ||
| 55 | /* Initialises a new parameter at the end of list */ | 80 | /* Initialises a new parameter at the end of list */ |
