opkg: adding the hash_table_remove API, not using yet.
[project/opkg-lede.git] / libopkg / xregex.c
1 /* xregex.c - regex functions with error messages
2
3 Carl D. Worth
4
5 Copyright (C) 2001 University of Southern California
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16 */
17
18 #include "includes.h"
19
20 #include "xregex.h"
21
22 static void print_regcomp_err(const regex_t *preg, int err);
23
24 int xregcomp(regex_t *preg, const char *regex, int cflags)
25 {
26 int err;
27 err = regcomp(preg, regex, cflags);
28 if (err) {
29 print_regcomp_err(preg, err);
30 }
31
32 return err;
33 }
34
35 static void print_regcomp_err(const regex_t *preg, int err)
36 {
37 int size;
38 char *error;
39
40 fprintf(stderr, "%s: Error compiling regex:", __FUNCTION__);
41 size = regerror(err, preg, 0, 0);
42 error = calloc(1, size);
43 if (error) {
44 regerror(err, preg, error, size);
45 fprintf(stderr, "%s\n", error);
46 }
47 free(error);
48 }