From 88fe8ed29e7396372cab9b3fe3182b0f57e3d3e8 Mon Sep 17 00:00:00 2001 From: Colin Clark Date: Sun, 3 Oct 2021 11:58:41 +0100 Subject: [PATCH] Bug fix: Non-portable functions Using argv[0] does not work with AppImages: it contains the path to where the AppImage was called from, and not the path where the executable is running. This solution uses the whereami package from: https://github.com/gpakosz/whereami --- src/Makefile.am | 2 ++ src/main.c | 21 +++++++++------------ 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/src/Makefile.am b/src/Makefile.am index db943274..5fbc303e 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -300,6 +300,8 @@ geeqie_SOURCES = \ view_dir_tree.c \ view_dir_tree.h \ view_file.h \ + whereami.c \ + whereami.h \ window.c \ window.h \ lua.c \ diff --git a/src/main.c b/src/main.c index 3bfdedde..2cef1c94 100644 --- a/src/main.c +++ b/src/main.c @@ -58,6 +58,7 @@ #include "histogram.h" #include "pixbuf_util.h" #include "glua.h" +#include "whereami.h" #ifdef HAVE_CLUTTER #include @@ -1251,19 +1252,15 @@ static void create_application_paths(gchar *argv[]) { gchar *dirname; gchar *tmp; - gchar **env; - - env = g_get_environ(); + gint length; + gchar *path; - if (argv[0][0] == G_DIR_SEPARATOR) - { - gq_executable_path = g_strdup(argv[0]); - } - else - { - gq_executable_path = g_build_filename(g_environ_getenv(env, "PWD"), argv[0], NULL); - } + length = wai_getExecutablePath(NULL, 0, NULL); + path = (gchar *)malloc(length + 1); + wai_getExecutablePath(path, length, NULL); + path[length] = '\0'; + gq_executable_path = g_strdup(path); dirname = g_path_get_dirname(gq_executable_path); // default is /usr/bin/ gq_prefix = g_path_get_dirname(dirname); @@ -1277,7 +1274,7 @@ static void create_application_paths(gchar *argv[]) g_free(tmp); g_free(dirname); - g_strfreev(env); + g_free(path); } gint main(gint argc, gchar *argv[]) -- 2.20.1