Bug fix: Non-portable functions
[geeqie.git] / src / main.c
index e7f6b69..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>
@@ -1247,23 +1248,20 @@ static void setup_sigbus_handler(void)
  * They are now variables, all defined relative to one level above the
  * directory that the executable is run from.
  */
-static void create_application_paths()
+static void create_application_paths(gchar *argv[])
 {
-       gchar buf[1024];
        gchar *dirname;
        gchar *tmp;
+       gint length;
+       gchar *path;
 
-       memset(buf, 0, sizeof(buf));
-       if (readlink("/proc/self/exe", buf, sizeof(buf) - 1) < 0)
-               {
-               /* There was an error. Perhaps the path does not exist
-                * or the buffer is not big enough. */
-               log_printf("Can't get path from /proc/self/exe");
-               exit(1);
-               }
+       length = wai_getExecutablePath(NULL, 0, NULL);
+       path = (gchar *)malloc(length + 1);
+       wai_getExecutablePath(path, length, NULL);
+       path[length] = '\0';
 
-       gq_executable_path = g_strdup(buf);
-       dirname = g_path_get_dirname(buf); // default is /usr/bin/
+       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);
 
        gq_localedir = g_build_filename(gq_prefix, "share", "locale", NULL);
@@ -1276,6 +1274,7 @@ static void create_application_paths()
 
        g_free(tmp);
        g_free(dirname);
+       g_free(path);
 }
 
 gint main(gint argc, gchar *argv[])
@@ -1299,7 +1298,7 @@ gint main(gint argc, gchar *argv[])
        /* init execution time counter (debug only) */
        init_exec_time();
 
-       create_application_paths();
+       create_application_paths(argv);
 
        /* setup locale, i18n */
        setlocale(LC_ALL, "");