commit 62830860835ff03b1b721b1d6c8c54d32fe889d7
parent 046e11cde5d36a943bb0ca398e122ac564c111f9
Author: Brian Swetland <swetland@frotz.net>
Date: Sat, 9 Feb 2013 21:25:12 -0800
io: linux support for finding executable path
Diffstat:
1 file changed, 13 insertions(+), 1 deletion(-)
diff --git a/common/io.cc b/common/io.cc
@@ -21,7 +21,7 @@
extern const char *load_file_base_path;
-static char base_path[1024];
+static char base_path[1024 + 8];
#ifdef _WIN32
#include <windows.h>
@@ -37,7 +37,19 @@ void init_io(void) {
}
}
#else
+#include <unistd.h>
void init_io(void) {
+ char *x;
+ int r;
+ r = readlink("/proc/self/exe", base_path, 1024);
+ if (r < 0)
+ return;
+ x = strrchr(buf,'/');
+ if (x) {
+ x[1] = 0;
+ strcat(base_path,"assets/");
+ load_file_base_path = base_path;
+ }
}
#endif