[libvirt] [PATCH 4/5] util: file: Replace use of 'strsep' with virStringSplit

Peter Krempa posted 5 patches 6 years, 2 months ago
[libvirt] [PATCH 4/5] util: file: Replace use of 'strsep' with virStringSplit
Posted by Peter Krempa 6 years, 2 months ago
Use our helper instead of the gnulib one.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
---
 src/util/virfile.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/src/util/virfile.c b/src/util/virfile.c
index c077639c1c..55705c8463 100644
--- a/src/util/virfile.c
+++ b/src/util/virfile.c
@@ -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;
@@ -1660,14 +1659,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);
     }
-- 
2.23.0

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

Re: [libvirt] [PATCH 4/5] util: file: Replace use of 'strsep' with virStringSplit
Posted by Pavel Hrdina 6 years, 2 months ago
On Thu, Nov 14, 2019 at 11:43:32AM +0100, Peter Krempa wrote:
> Use our helper instead of the gnulib one.
> 
> Signed-off-by: Peter Krempa <pkrempa@redhat.com>
> ---
>  src/util/virfile.c | 15 ++++++++-------
>  1 file changed, 8 insertions(+), 7 deletions(-)

Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH 4/5] util: file: Replace use of 'strsep' with virStringSplit
Posted by Ján Tomko 6 years, 2 months ago
On Thu, Nov 14, 2019 at 11:43:32AM +0100, Peter Krempa wrote:
>Use our helper instead of the gnulib one.
>
>Signed-off-by: Peter Krempa <pkrempa@redhat.com>
>---
> src/util/virfile.c | 15 ++++++++-------
> 1 file changed, 8 insertions(+), 7 deletions(-)
>

Reviewed-by: Ján Tomko <jtomko@redhat.com>

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