Eric Andersen | aad1a88 | 2001-03-16 22:47:14 +0000 | [diff] [blame] | 1 | /* vi: set sw=4 ts=4: */ |
| 2 | /* |
| 3 | * Utility routines. |
| 4 | * |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 5 | * Copyright (C) many different people. |
Eric Andersen | cb81e64 | 2003-07-14 21:21:08 +0000 | [diff] [blame] | 6 | * If you wrote this, please acknowledge your work. |
Eric Andersen | aad1a88 | 2001-03-16 22:47:14 +0000 | [diff] [blame] | 7 | * |
Bernhard Reutner-Fischer | b1629b1 | 2006-05-19 19:29:19 +0000 | [diff] [blame] | 8 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. |
Eric Andersen | aad1a88 | 2001-03-16 22:47:14 +0000 | [diff] [blame] | 9 | */ |
| 10 | |
Eric Andersen | aad1a88 | 2001-03-16 22:47:14 +0000 | [diff] [blame] | 11 | #include "libbb.h" |
"Vladimir N. Oleynik" | 23f62fc | 2005-09-14 16:59:11 +0000 | [diff] [blame] | 12 | #include "xregex.h" |
Eric Andersen | aad1a88 | 2001-03-16 22:47:14 +0000 | [diff] [blame] | 13 | |
Denis Vlasenko | e865e81 | 2006-12-21 13:24:58 +0000 | [diff] [blame] | 14 | char* regcomp_or_errmsg(regex_t *preg, const char *regex, int cflags) |
Eric Andersen | aad1a88 | 2001-03-16 22:47:14 +0000 | [diff] [blame] | 15 | { |
Denis Vlasenko | 3f3190e | 2006-12-21 00:22:03 +0000 | [diff] [blame] | 16 | int ret = regcomp(preg, regex, cflags); |
| 17 | if (ret) { |
Eric Andersen | aad1a88 | 2001-03-16 22:47:14 +0000 | [diff] [blame] | 18 | int errmsgsz = regerror(ret, preg, NULL, 0); |
| 19 | char *errmsg = xmalloc(errmsgsz); |
| 20 | regerror(ret, preg, errmsg, errmsgsz); |
Denis Vlasenko | e865e81 | 2006-12-21 13:24:58 +0000 | [diff] [blame] | 21 | return errmsg; |
| 22 | } |
| 23 | return NULL; |
| 24 | } |
| 25 | |
| 26 | void 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 | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 30 | bb_error_msg_and_die("xregcomp: %s", errmsg); |
Eric Andersen | aad1a88 | 2001-03-16 22:47:14 +0000 | [diff] [blame] | 31 | } |
| 32 | } |