-static int ignorelist_append_regex(ignorelist_t *il, const char *entry)
-{
- int rcompile;
- regex_t *regtemp;
- int errsize;
- char *regerr = NULL;
- ignorelist_item_t *new;
-
- /* create buffer */
- if ((regtemp = malloc(sizeof(regex_t))) == NULL)
- {
- ERROR ("cannot allocate new config entry");
- return (1);
- }
- memset (regtemp, '\0', sizeof(regex_t));
-
- /* compile regex */
- if ((rcompile = regcomp (regtemp, entry, REG_EXTENDED)) != 0)
- {
- /* prepare message buffer */
- errsize = regerror(rcompile, regtemp, NULL, 0);
- if (errsize)
- regerr = smalloc(errsize);
- /* get error message */
- if (regerror (rcompile, regtemp, regerr, errsize))
- {
- fprintf (stderr, "Cannot compile regex %s: %i/%s",
- entry, rcompile, regerr);
- ERROR ("Cannot compile regex %s: %i/%s",
- entry, rcompile, regerr);
- }
- else
- {
- fprintf (stderr, "Cannot compile regex %s: %i",
- entry, rcompile);
- ERROR ("Cannot compile regex %s: %i",
- entry, rcompile);
- }
-
- if (errsize)
- sfree (regerr);
- regfree (regtemp);
- sfree (regtemp);
- return (1);
- }
- DEBUG("regex compiled: %s - %i", entry, rcompile);
-
- /* create new entry */
- if ((new = malloc(sizeof(ignorelist_item_t))) == NULL)
- {
- ERROR ("cannot allocate new config entry");
- regfree (regtemp);
- sfree (regtemp);
- return (1);
- }
- memset (new, '\0', sizeof(ignorelist_item_t));
- new->rmatch = regtemp;
-
- /* append new entry */
- ignorelist_append (il, new);
-
- return (0);
-} /* int ignorelist_append_regex(ignorelist_t *il, const char *entry) */
+static int ignorelist_append_regex(ignorelist_t *il, const char *re_str) {
+ regex_t *re;
+ ignorelist_item_t *entry;
+ int status;
+
+ re = calloc(1, sizeof(*re));
+ if (re == NULL) {
+ ERROR("ignorelist_append_regex: calloc failed.");
+ return ENOMEM;
+ }
+
+ status = regcomp(re, re_str, REG_EXTENDED);
+ if (status != 0) {
+ char errbuf[1024];
+ (void)regerror(status, re, errbuf, sizeof(errbuf));
+ ERROR("utils_ignorelist: regcomp failed: %s", errbuf);
+ ERROR("ignorelist_append_regex: Compiling regular expression \"%s\" "
+ "failed: %s",
+ re_str, errbuf);
+ sfree(re);
+ return status;
+ }
+
+ entry = calloc(1, sizeof(*entry));
+ if (entry == NULL) {
+ ERROR("ignorelist_append_regex: calloc failed.");
+ regfree(re);
+ sfree(re);
+ return ENOMEM;
+ }
+ entry->rmatch = re;
+
+ ignorelist_append(il, entry);
+ return 0;
+} /* int ignorelist_append_regex */