util: add eregcomp: show descriptive error message on regcomp error

This commit is contained in:
Hiltjo Posthuma
2014-11-16 15:16:14 +01:00
committed by sin
parent 25e3e068ed
commit ce90cc57d4
3 changed files with 31 additions and 0 deletions

25
util/eregcomp.c Normal file
View File

@@ -0,0 +1,25 @@
#include <regex.h>
#include <stdio.h>
#include <sys/types.h>
#include "../util.h"
int
enregcomp(int status, regex_t *preg, const char *regex, int cflags)
{
char errbuf[BUFSIZ] = "";
int r;
if((r = regcomp(preg, regex, cflags)) == 0)
return r;
regerror(r, preg, errbuf, sizeof(errbuf));
enprintf(status, "invalid regex: %s\n", errbuf);
return r;
}
int
eregcomp(regex_t *preg, const char *regex, int cflags)
{
return enregcomp(1, preg, regex, cflags);
}