From 54317d94aef5d2f648eef5915a23b48b9679c229 Mon Sep 17 00:00:00 2001 From: Yves Rizoud Date: Thu, 11 Mar 2010 20:40:25 +0000 Subject: [PATCH] Fix issue 326: Program doesn't find data directory on some linux (attempt. Tested ok on Debian) git-svn-id: svn://pulkomandy.tk/GrafX2/trunk@1380 416bcca6-2ee7-4201-b75f-2eb2f807beb1 --- src/errors.h | 2 +- src/setup.c | 18 +++++++++++++++--- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/errors.h b/src/errors.h index 4ff652ad..b9dd23c9 100644 --- a/src/errors.h +++ b/src/errors.h @@ -51,4 +51,4 @@ void Warning_function(const char *message, const char *filename, int line_number /// some information about the calling function, and then resume silently. /// This is most useful in debugger so you can put a breakpoint on /// ::Warning_function and examine the stack trace. -#define Warning(msg) Warning_function(msg, __FILE__,__LINE__,__func__) \ No newline at end of file +#define Warning(msg) Warning_function(msg, __FILE__,__LINE__,__func__) diff --git a/src/setup.c b/src/setup.c index c3f9e1a5..a9deb3f4 100644 --- a/src/setup.c +++ b/src/setup.c @@ -35,6 +35,9 @@ #import #elif defined(__FreeBSD__) #import +#elif defined(__linux__) + #include + #include #endif #include "struct.h" @@ -77,11 +80,20 @@ void Set_program_directory(ARG_UNUSED const char * argv0,char * program_dir) #elif defined(__amigaos4__) || defined(__AROS__) || defined(__MORPHOS__) || defined(__amigaos__) strcpy(program_dir,"PROGDIR:"); + // Linux: argv[0] unreliable + #elif defined(__linux__) + if (argv0[0]!='/') + { + char path[PATH_MAX]; + readlink("/proc/self/exe", path, sizeof(path)); + Extract_path(program_dir, path); + return; + } + Extract_path(program_dir, argv0); + // Others: The part of argv[0] before the executable name. // Keep the last \ or /. - // Note that on Unix, once installed, the executable is called from a shell - // script sitting in /usr/local/bin/, this allows argv[0] to contain the full - // path. On Windows, Mingw32 already provides the full path in all cases. + // On Windows, Mingw32 already provides the full path in all cases. #else Extract_path(program_dir, argv0); #endif