]> xenbits.xensource.com Git - libvirt.git/commitdiff
util: file: Replace use of 'strsep' with virStringSplit
authorPeter Krempa <pkrempa@redhat.com>
Thu, 14 Nov 2019 09:25:31 +0000 (10:25 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Thu, 14 Nov 2019 14:50:43 +0000 (15:50 +0100)
Use our helper instead of the gnulib one.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/util/virfile.c

index c7620e49d56154dfccb891b069164f0a8c687764..cb6cfc0fe72f610c096d51b85482eba8b8c2d5fe 100644 (file)
@@ -1634,9 +1634,8 @@ char *
 virFindFileInPath(const char *file)
 {
     const char *origpath = NULL;
-    g_autofree char *path = NULL;
-    char *pathiter;
-    char *pathseg;
+    VIR_AUTOSTRINGLIST paths = NULL;
+    char **pathiter;
 
     if (file == NULL)
         return NULL;
@@ -1668,14 +1667,16 @@ virFindFileInPath(const char *file)
     origpath = getenv("PATH");
     if (!origpath)
         origpath = "/bin:/usr/bin";
-    path = g_strdup(origpath);
 
     /* for each path segment, append the file to search for and test for
      * it. return it if found.
      */
-    pathiter = path;
-    while ((pathseg = strsep(&pathiter, ":")) != NULL) {
-        g_autofree char *fullpath = g_strdup_printf("%s/%s", pathseg, file);
+
+    if (!(paths = virStringSplit(origpath, ":", 0)))
+        return NULL;
+
+    for (pathiter = paths; *pathiter; pathiter++) {
+        g_autofree char *fullpath = g_strdup_printf("%s/%s", *pathiter, file);
         if (virFileIsExecutable(fullpath))
             return g_steal_pointer(&fullpath);
     }