[PATCH 07/16] test_driver: Rewrite testBuildFilename

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

 



Use glib functions to do the relative name lookup instead of manual
assembly.

Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx>
---
 src/test/test_driver.c | 35 ++++++-----------------------------
 1 file changed, 6 insertions(+), 29 deletions(-)

diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index 71ab04aa1a..30a1959589 100644
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -739,32 +739,14 @@ testDomainStartState(testDriverPtr privconn,
 static char *testBuildFilename(const char *relativeTo,
                                const char *filename)
 {
-    char *offset;
-    int baseLen;
-    char *ret;
+    g_autofree char *basename = NULL;

-    if (!filename || filename[0] == '\0')
-        return NULL;
-    if (filename[0] == '/') {
-        ret = g_strdup(filename);
-        return ret;
-    }
+    if (g_path_is_absolute(filename))
+        return g_strdup(filename);

-    offset = strrchr(relativeTo, '/');
-    if ((baseLen = (offset-relativeTo+1))) {
-        char *absFile;
-        int totalLen = baseLen + strlen(filename) + 1;
-        absFile = g_new0(char, totalLen);
-        if (virStrncpy(absFile, relativeTo, baseLen, totalLen) < 0) {
-            VIR_FREE(absFile);
-            return NULL;
-        }
-        strcat(absFile, filename);
-        return absFile;
-    } else {
-        ret = g_strdup(filename);
-        return ret;
-    }
+    basename = g_path_get_dirname(relativeTo);
+
+    return g_strdup_printf("%s/%s", basename, filename);
 }

 static xmlNodePtr
@@ -777,11 +759,6 @@ testParseXMLDocFromFile(xmlNodePtr node, const char *file, const char *type)

     if ((relFile = virXMLPropString(node, "file"))) {
         absFile = testBuildFilename(file, relFile);
-        if (!absFile) {
-            virReportError(VIR_ERR_INTERNAL_ERROR,
-                           _("resolving %s filename"), type);
-            return NULL;
-        }

         if (!(doc = virXMLParse(absFile, NULL, type)))
             goto error;
-- 
2.29.2




[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