blob: 157132c1f8768ff4c100eefb3a85dab50ecd7c1b [file] [log] [blame]
Eric Andersenaad1a882001-03-16 22:47:14 +00001/* vi: set sw=4 ts=4: */
2/*
3 * Utility routines.
4 *
Eric Andersenc7bda1c2004-03-15 08:29:22 +00005 * Copyright (C) many different people.
Eric Andersencb81e642003-07-14 21:21:08 +00006 * If you wrote this, please acknowledge your work.
Eric Andersenaad1a882001-03-16 22:47:14 +00007 *
Bernhard Reutner-Fischerb1629b12006-05-19 19:29:19 +00008 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
Eric Andersenaad1a882001-03-16 22:47:14 +00009 */
10
Eric Andersenaad1a882001-03-16 22:47:14 +000011#include "libbb.h"
"Vladimir N. Oleynik"23f62fc2005-09-14 16:59:11 +000012#include "xregex.h"
Eric Andersenaad1a882001-03-16 22:47:14 +000013
Denis Vlasenkoe865e812006-12-21 13:24:58 +000014char* regcomp_or_errmsg(regex_t *preg, const char *regex, int cflags)
Eric Andersenaad1a882001-03-16 22:47:14 +000015{
Denis Vlasenko3f3190e2006-12-21 00:22:03 +000016 int ret = regcomp(preg, regex, cflags);
17 if (ret) {
Eric Andersenaad1a882001-03-16 22:47:14 +000018 int errmsgsz = regerror(ret, preg, NULL, 0);
19 char *errmsg = xmalloc(errmsgsz);
20 regerror(ret, preg, errmsg, errmsgsz);
Denis Vlasenkoe865e812006-12-21 13:24:58 +000021 return errmsg;
22 }
23 return NULL;
24}
25
26void xregcomp(regex_t *preg, const char *regex, int cflags)
27{
28 char *errmsg = regcomp_or_errmsg(preg, regex, cflags);
29 if (errmsg) {
Manuel Novoa III cad53642003-03-19 09:13:01 +000030 bb_error_msg_and_die("xregcomp: %s", errmsg);
Eric Andersenaad1a882001-03-16 22:47:14 +000031 }
32}