]> xenbits.xensource.com Git - libvirt.git/commitdiff
util: use GRegex in virStringMatch
authorJán Tomko <jtomko@redhat.com>
Wed, 13 Nov 2019 15:01:19 +0000 (16:01 +0100)
committerJán Tomko <jtomko@redhat.com>
Thu, 14 Nov 2019 16:45:40 +0000 (17:45 +0100)
Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
src/util/virstring.c

index 121a5c33b0b0b7547b6002a1a3bfafa2252bff8a..40c83841e9b6cd431df249b86175bd64ad55eda5 100644 (file)
@@ -19,7 +19,6 @@
 #include <config.h>
 
 #include <glib/gprintf.h>
-#include <regex.h>
 #include <locale.h>
 
 #include "c-ctype.h"
@@ -1089,24 +1088,18 @@ bool
 virStringMatch(const char *str,
                const char *regexp)
 {
-    regex_t re;
-    int rv;
+    g_autoptr(GRegex) regex = NULL;
+    g_autoptr(GError) err = NULL;
 
     VIR_DEBUG("match '%s' for '%s'", str, regexp);
 
-    if ((rv = regcomp(&re, regexp, REG_EXTENDED | REG_NOSUB)) != 0) {
-        char error[100];
-        regerror(rv, &re, error, sizeof(error));
-        VIR_WARN("error while compiling regular expression '%s': %s",
-                 regexp, error);
+    regex = g_regex_new(regexp, 0, 0, &err);
+    if (!regex) {
+        VIR_WARN("Failed to compile regex %s", err->message);
         return false;
     }
 
-    rv = regexec(&re, str, 0, NULL, 0);
-
-    regfree(&re);
-
-    return rv == 0;
+    return g_regex_match(regex, str, 0, NULL);
 }
 
 /**