1 /*
2 * xregcomp.c: regcomp with error checking
3 *
4 * Copyright (C) 2008 Colin Watson.
5 *
6 * This file is part of man-db.
7 *
8 * man-db is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * man-db is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with man-db; if not, write to the Free Software Foundation,
20 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
23 #ifdef HAVE_CONFIG_H
24 # include "config.h"
25 #endif /* HAVE_CONFIG_H */
26
27 #include <stddef.h>
28
29 #include "regex.h"
30
31 #include "gettext.h"
32 #include <locale.h>
33 #define _(String) gettext (String)
34
35 #include "manconfig.h"
36
37 #include "fatal.h"
38 #include "xalloc.h"
39 #include "xregcomp.h"
40
41 void xregcomp (regex_t *preg, const char *regex, int cflags)
42 {
43 int err = regcomp (preg, regex, cflags);
44 if (err) {
45 size_t errstrsize;
46 char *errstr;
47 errstrsize = regerror (err, preg, NULL, 0);
48 errstr = xmalloc (errstrsize);
49 regerror (err, preg, errstr, errstrsize);
50 fatal (0, _("fatal: regex `%s': %s"), regex, errstr);
51 }
52 }