From 38bc2e8c1b06382126b28c8eeeb30475876517ac Mon Sep 17 00:00:00 2001 From: Peter Krempa Date: Thu, 14 Nov 2019 10:25:31 +0100 Subject: [PATCH] util: file: Replace use of 'strsep' with virStringSplit MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use our helper instead of the gnulib one. Signed-off-by: Peter Krempa Reviewed-by: Pavel Hrdina Reviewed-by: Ján Tomko --- 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 c7620e49d5..cb6cfc0fe7 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; @@ -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); }