blob: d106f85749dfdf3c7c6501b1fb4d8d88691b5fd4 [file] [log] [blame]
lh9ed821d2023-04-07 01:36:19 -07001/* vi: set sw=4 ts=4: */
2/*
3 * Utility routines.
4 *
5 * Copyright (C) many different people.
6 * If you wrote this, please acknowledge your work.
7 *
8 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
9 */
10
11#include "libbb.h"
12
13#if defined(__UC_LIBC__USE_REGEXP_H__)
14
15#include <regexp.h>
16
17void xregcomp(regex_t *preg, const char *reg, int cflags)
18{
19 regexp *ret;
20 const char *r;
21 r = reg;
22 if (cflags)
23 bb_error_msg_and_die("xregcomp: no support for -i");
24 ret = regcomp(r);
25 if (ret == NULL) {
26 regerror("cannot compile expression");
27 exit(1);
28 }
29 *preg = ret;
30}
31
32#else
33
34#include "xregex.h"
35
36char* FAST_FUNC regcomp_or_errmsg(regex_t *preg, const char *regex, int cflags)
37{
38 int ret = regcomp(preg, regex, cflags);
39 if (ret) {
40 int errmsgsz = regerror(ret, preg, NULL, 0);
41 char *errmsg = xmalloc(errmsgsz);
42 regerror(ret, preg, errmsg, errmsgsz);
43 return errmsg;
44 }
45 return NULL;
46}
47
48void FAST_FUNC xregcomp(regex_t *preg, const char *regex, int cflags)
49{
50 char *errmsg = regcomp_or_errmsg(preg, regex, cflags);
51 if (errmsg) {
52 bb_error_msg_and_die("bad regex '%s': %s", regex, errmsg);
53 }
54}
55#endif
56
57/* END CODE */
58/*
59Local Variables:
60c-file-style: "linux"
61c-basic-offset: 4
62tab-width: 4
63End:
64*/