提交 38bc2e8c 编写于 作者: P Peter Krempa

util: file: Replace use of 'strsep' with virStringSplit

Use our helper instead of the gnulib one.
Signed-off-by: NPeter Krempa <pkrempa@redhat.com>
Reviewed-by: NPavel Hrdina <phrdina@redhat.com>
Reviewed-by: NJán Tomko <jtomko@redhat.com>
上级 4bb2c51a
...@@ -1634,9 +1634,8 @@ char * ...@@ -1634,9 +1634,8 @@ char *
virFindFileInPath(const char *file) virFindFileInPath(const char *file)
{ {
const char *origpath = NULL; const char *origpath = NULL;
g_autofree char *path = NULL; VIR_AUTOSTRINGLIST paths = NULL;
char *pathiter; char **pathiter;
char *pathseg;
if (file == NULL) if (file == NULL)
return NULL; return NULL;
...@@ -1668,14 +1667,16 @@ virFindFileInPath(const char *file) ...@@ -1668,14 +1667,16 @@ virFindFileInPath(const char *file)
origpath = getenv("PATH"); origpath = getenv("PATH");
if (!origpath) if (!origpath)
origpath = "/bin:/usr/bin"; origpath = "/bin:/usr/bin";
path = g_strdup(origpath);
/* for each path segment, append the file to search for and test for /* for each path segment, append the file to search for and test for
* it. return it if found. * it. return it if found.
*/ */
pathiter = path;
while ((pathseg = strsep(&pathiter, ":")) != NULL) { if (!(paths = virStringSplit(origpath, ":", 0)))
g_autofree char *fullpath = g_strdup_printf("%s/%s", pathseg, file); return NULL;
for (pathiter = paths; *pathiter; pathiter++) {
g_autofree char *fullpath = g_strdup_printf("%s/%s", *pathiter, file);
if (virFileIsExecutable(fullpath)) if (virFileIsExecutable(fullpath))
return g_steal_pointer(&fullpath); return g_steal_pointer(&fullpath);
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册