Bug fix: Non-portable functions
authorColin Clark <colin.clark@cclark.uk>
Sun, 3 Oct 2021 10:58:41 +0000 (11:58 +0100)
committerColin Clark <colin.clark@cclark.uk>
Sun, 3 Oct 2021 10:58:41 +0000 (11:58 +0100)
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
src/main.c

index db94327..5fbc303 100644 (file)
@@ -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           \
index 3bfdedd..2cef1c9 100644 (file)
@@ -58,6 +58,7 @@
 #include "histogram.h"
 #include "pixbuf_util.h"
 #include "glua.h"
+#include "whereami.h"
 
 #ifdef HAVE_CLUTTER
 #include <clutter-gtk/clutter-gtk.h>
@@ -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[])