blob: a3b1aa8a7bc32887bc3f6abaf9c2d612c51b4630 [file] [log] [blame]
Patrick Georgi55189c92020-05-10 20:09:31 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Stefan Reinauer6540ae52007-07-12 16:35:42 +00002
3#include <stdarg.h>
4#include "common.h"
5#include "reg_expr.h"
6
7/****************************************************************************
Patrick Georgibf649852011-01-28 07:40:08 +00008 * compile_reg_expr
Stefan Reinauer6540ae52007-07-12 16:35:42 +00009 *
Patrick Georgibf649852011-01-28 07:40:08 +000010 * Compile a regular expression.
Stefan Reinauer6540ae52007-07-12 16:35:42 +000011 ****************************************************************************/
Patrick Georgibf649852011-01-28 07:40:08 +000012void compile_reg_expr(int cflags, const char *expr, regex_t *reg)
Stefan Reinauer90b96b62010-01-13 21:00:23 +000013{
14 static const size_t ERROR_BUF_SIZE = 256;
15 char error_msg[ERROR_BUF_SIZE];
Patrick Georgibf649852011-01-28 07:40:08 +000016 int result;
Stefan Reinauer6540ae52007-07-12 16:35:42 +000017
Patrick Georgibf649852011-01-28 07:40:08 +000018 if ((result = regcomp(reg, expr, cflags)) != 0) {
19 regerror(result, reg, error_msg, ERROR_BUF_SIZE);
20 fprintf(stderr, "%s: %s\n", prog_name, error_msg);
21 exit(1);
Stefan Reinauer90b96b62010-01-13 21:00:23 +000022 }
Stefan Reinauer90b96b62010-01-13 21:00:23 +000023}