diff options
| author | ruki <[email protected]> | 2020-02-26 22:49:57 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2020-02-26 10:59:44 +0800 |
| commit | 1cfb98b4e65d73ccddcb396a510f1ffa9d1f28ac (patch) | |
| tree | a428af1defd84244b35cdc556d607a9a473c4b11 /core/src | |
| parent | 33183c28a74286f34d81b228c91b616af17a1db7 (diff) | |
readlink from programfile
Diffstat (limited to 'core/src')
| -rw-r--r-- | core/src/xmake/machine.c | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/core/src/xmake/machine.c b/core/src/xmake/machine.c index f086dd17f..f9a908c23 100644 --- a/core/src/xmake/machine.c +++ b/core/src/xmake/machine.c @@ -34,6 +34,7 @@ # include <io.h> # include <fcntl.h> #elif defined(TB_CONFIG_OS_MACOSX) +# include <unistd.h> # include <mach-o/dyld.h> #elif defined(TB_CONFIG_OS_LINUX) # include <unistd.h> @@ -494,9 +495,20 @@ static tb_bool_t xm_machine_get_program_directory(xm_machine_t* machine, tb_char // get it from program file path if (programfile) { + // get real program file path from the symbol link +#ifndef TB_CONFIG_OS_WINDOWS + tb_char_t programpath[TB_PATH_MAXN]; + tb_long_t size = readlink(programfile, programpath, sizeof(programpath)); + if (size >= 0 && size < sizeof(programpath)) + programpath[size] = '\0'; + else tb_strlcpy(programpath, programfile, sizeof(programpath)); +#else + tb_char_t const* programpath = programfile; +#endif + // get the root directory tb_char_t data[TB_PATH_MAXN]; - tb_char_t const* rootdir = tb_path_directory(programfile, data, sizeof(data)); + tb_char_t const* rootdir = tb_path_directory(programpath, data, sizeof(data)); tb_assert_and_check_break(rootdir); // find the program (lua) directory |
