diff options
Diffstat (limited to 'utils')
-rw-r--r-- | utils/utils.c | 22 | ||||
-rw-r--r-- | utils/utils.h | 3 |
2 files changed, 25 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); + } +} + diff --git a/utils/utils.h b/utils/utils.h index 3ca3072af..e3a210352 100644 --- a/utils/utils.h +++ b/utils/utils.h @@ -10,6 +10,8 @@ #include <stdbool.h> #include <stdlib.h> +#include <sys/types.h> +#include <regex.h> #include "libxml/encoding.h" void die(const char * const error); @@ -27,5 +29,6 @@ char *squash_tolat1(xmlChar *s); char *url_join(char *rel_url, char *base_url); char *get_host_from_url(char* url); bool is_dir(const char *path); +void regcomp_wrapper(regex_t *preg, const char *regex, int cflags); #endif |