aboutsummaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
authorDavid Bremner <bremner@debian.org>2011-10-23 17:52:19 -0300
committerDavid Bremner <bremner@debian.org>2011-10-30 23:10:38 -0300
commit7a87830f5eb32373bc17235e9d178d383830dc64 (patch)
treecbdfb839d39797ea4a87292fffe2b01a08f053f2 /util
parent1dedfc90f6eee7cad10f1a1ceb39a7a1c4dbd1b1 (diff)
xregcomp: don't consider every regex compilation failure an internal error.
This pushes the error handling up one step, but makes the function more flexible. Running out of memory still triggers an internal error, in the spirit of other xutils functions.
Diffstat (limited to 'util')
-rw-r--r--util/xutil.c7
-rw-r--r--util/xutil.h3
2 files changed, 7 insertions, 3 deletions
diff --git a/util/xutil.c b/util/xutil.c
index 15ff765..ac496da 100644
--- a/util/xutil.c
+++ b/util/xutil.c
@@ -99,7 +99,7 @@ xstrndup (const char *s, size_t n)
return ret;
}
-void
+int
xregcomp (regex_t *preg, const char *regex, int cflags)
{
int rerr;
@@ -110,9 +110,12 @@ xregcomp (regex_t *preg, const char *regex, int cflags)
char *error = xmalloc (error_size);
regerror (rerr, preg, error, error_size);
- INTERNAL_ERROR ("compiling regex %s: %s\n",
+ fprintf (stderr, "compiling regex %s: %s\n",
regex, error);
+ free (error);
+ return 1;
}
+ return 0;
}
int
diff --git a/util/xutil.h b/util/xutil.h
index fd77f73..9299256 100644
--- a/util/xutil.h
+++ b/util/xutil.h
@@ -43,7 +43,8 @@ xstrdup (const char *s);
char *
xstrndup (const char *s, size_t n);
-void
+/* Returns 0 for successful compilation, 1 otherwise */
+int
xregcomp (regex_t *preg, const char *regex, int cflags);
int