[PATCH 11/12] util: use GRegex in virStringMatch

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Signed-off-by: Ján Tomko <jtomko@xxxxxxxxxx>
---
 src/util/virstring.c | 22 ++++++++--------------
 1 file changed, 8 insertions(+), 14 deletions(-)

diff --git a/src/util/virstring.c b/src/util/virstring.c
index 3da793c87a..6add2278d8 100644
--- a/src/util/virstring.c
+++ b/src/util/virstring.c
@@ -19,7 +19,6 @@
 #include <config.h>
 
 #include <glib/gprintf.h>
-#include <regex.h>
 #include <locale.h>
 
 #include "c-ctype.h"
@@ -1089,24 +1088,19 @@ 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);
-        return false;
+    regex = g_regex_new(regexp, 0, 0, &err);
+    if (!regex) {
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       _("Failed to compile regex %s"), err->message);
+        return -1;
     }
 
-    rv = regexec(&re, str, 0, NULL, 0);
-
-    regfree(&re);
-
-    return rv == 0;
+    return g_regex_match(regex, str, 0, NULL);
 }
 
 /**
-- 
2.21.0

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux