summaryrefslogtreecommitdiff
path: root/utils/utils.c
diff options
context:
space:
mode:
Diffstat (limited to 'utils/utils.c')
-rw-r--r--utils/utils.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/utils/utils.c b/utils/utils.c
index 2ebdf9e5d..cb331a55f 100644
--- a/utils/utils.c
+++ b/utils/utils.c
@@ -13,6 +13,8 @@
#include <string.h>
#include <sys/stat.h>
#include <uri.h>
+#include <sys/types.h>
+#include <regex.h>
#include "libxml/encoding.h"
#include "libxml/uri.h"
#include "netsurf/utils/log.h"
@@ -256,3 +258,23 @@ bool is_dir(const char *path)
return S_ISDIR(s.st_mode) ? true : false;
}
+
+
+/**
+ * Compile a regular expression, handling errors.
+ *
+ * Parameters as for regcomp(), see man regex.
+ */
+
+void regcomp_wrapper(regex_t *preg, const char *regex, int cflags)
+{
+ char errbuf[200];
+ int r;
+ r = regcomp(preg, regex, cflags);
+ if (r) {
+ regerror(r, preg, errbuf, sizeof errbuf);
+ fprintf(stderr, "Failed to compile regexp '%s'\n", regex);
+ die(errbuf);
+ }
+}
+