[glib: 1/2] gutils: Fix g_find_program_in_path() to return an absolute path
- From: Sebastian Dröge <sdroege src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib: 1/2] gutils: Fix g_find_program_in_path() to return an absolute path
- Date: Thu, 27 Jan 2022 10:50:37 +0000 (UTC)
commit 78dc1cc3cd669e9fb92ae7847bab2b308c0a8628
Author: Christoph Niethammer <christoph niethammer gmail com>
Date: Thu Jan 27 03:54:01 2022 +0100
gutils: Fix g_find_program_in_path() to return an absolute path
Fix a possibility of returning a relative path, in case PATH contains
a relative path. According to the doc, the function should return an
absolute path.
Signed-off-by: Christoph Niethammer <christoph niethammer gmail com>
glib/gutils.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
---
diff --git a/glib/gutils.c b/glib/gutils.c
index 6652d0ba0..6cc450607 100644
--- a/glib/gutils.c
+++ b/glib/gutils.c
@@ -456,7 +456,14 @@ g_find_program_in_path (const gchar *program)
!g_file_test (startp, G_FILE_TEST_IS_DIR))
{
gchar *ret;
- ret = g_strdup (startp);
+ if (g_path_is_absolute (startp)) {
+ ret = g_strdup (startp);
+ } else {
+ gchar *cwd = NULL;
+ cwd = g_get_current_dir ();
+ ret = g_build_filename (cwd, startp, NULL);
+ g_free (cwd);
+ }
g_free (freeme);
#ifdef G_OS_WIN32
g_free ((gchar *) path_copy);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]