[glib: 1/3] gutils: ensure g_find_program_in_path() return an absolute path
- From: Philip Withnall <pwithnall src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib: 1/3] gutils: ensure g_find_program_in_path() return an absolute path
- Date: Wed, 2 Jun 2021 12:57:47 +0000 (UTC)
commit dba1fce993b280e2c9481a0d94ec2cc0ddc26739
Author: Luke Yue <lukedyue gmail com>
Date: Sun May 30 17:51:36 2021 +0800
gutils: ensure g_find_program_in_path() return an absolute path
Fix a possibility of returning a relative path, according to the
doc, the function should return an absolute path.
Signed-off-by: Luke Yue <lukedyue gmail com>
glib/gutils.c | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)
---
diff --git a/glib/gutils.c b/glib/gutils.c
index f72a5a148..b7a2113d4 100644
--- a/glib/gutils.c
+++ b/glib/gutils.c
@@ -340,7 +340,17 @@ g_find_program_in_path (const gchar *program)
{
if (g_file_test (program, G_FILE_TEST_IS_EXECUTABLE) &&
!g_file_test (program, G_FILE_TEST_IS_DIR))
- return g_strdup (program);
+ {
+ gchar *out = NULL, *cwd = NULL;
+
+ if (g_path_is_absolute (program))
+ return g_strdup (program);
+
+ cwd = g_get_current_dir ();
+ out = g_build_filename (cwd, program, NULL);
+ g_free (cwd);
+ return g_steal_pointer (&out);
+ }
else
return NULL;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]