summaryrefslogtreecommitdiff
path: root/util/sbase/libutil/eregcomp.c
blob: 02c8698c012ffb879aa32a371afd6dd476286d93 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <sys/types.h>

#include <regex.h>
#include <stdio.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);
}