summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2017-04-15 21:34:36 +0800
committerruki <[email protected]>2017-04-15 21:34:36 +0800
commite523e7fc34144794aa837ce1aab2a9ff966496ba (patch)
treecec07e75993013d544b64e310d1b858e2aee22f1
parentb1e1276d43eb00b5e4d6d702a7e8ea03fcb78bed (diff)
attempt to get executable file on linux
-rw-r--r--core/src/xmake/machine.c25
1 files changed, 24 insertions, 1 deletions
diff --git a/core/src/xmake/machine.c b/core/src/xmake/machine.c
index b41b55dce..2db633946 100644
--- a/core/src/xmake/machine.c
+++ b/core/src/xmake/machine.c
@@ -37,6 +37,8 @@
# include <windows.h>
#elif defined(TB_CONFIG_OS_MACOSX)
# include <mach-o/dyld.h>
+#elif defined(TB_CONFIG_OS_LINUX)
+# include <unistd.h>
#endif
/* //////////////////////////////////////////////////////////////////////////////////////
@@ -202,7 +204,7 @@ static tb_bool_t xm_machine_main_get_program_directory(xm_machine_impl_t* impl,
}
#if defined(TB_CONFIG_OS_WINDOWS)
- // get the program directory
+ // get the executale file path as program directory
tb_size_t size = (tb_size_t)GetModuleFileName(tb_null, path, (DWORD)maxn);
tb_assert_and_check_break(size < maxn);
@@ -251,6 +253,27 @@ static tb_bool_t xm_machine_main_get_program_directory(xm_machine_impl_t* impl,
// ok
ok = tb_true;
}
+#elif defined(TB_CONFIG_OS_LINUX)
+ // get the executale file path as program directory
+ ssize_t size = readlink("/proc/self/exe", path, (size_t)maxn);
+ if (size > 0 && size < maxn)
+ {
+ // end
+ path[size] = '\0';
+
+ // get the directory
+ while (size-- > 0)
+ {
+ if (path[size] == '/')
+ {
+ path[size] = '\0';
+ break;
+ }
+ }
+
+ // ok
+ ok = tb_true;
+ }
#endif
} while (0);