diff options
| author | ruki <[email protected]> | 2020-05-09 00:00:16 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2020-05-09 00:00:16 +0800 |
| commit | 5d3b6b648cda34096b5a2529b8701724eab8bf6a (patch) | |
| tree | 9b6afed7285ec498780cc82bb4f1511fb95ecb6e /core/src/xmake/engine.c | |
| parent | e262531aaf602519e28860de672aeae78c2e5e26 (diff) | |
get self file for bsd file
Diffstat (limited to 'core/src/xmake/engine.c')
| -rw-r--r-- | core/src/xmake/engine.c | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/core/src/xmake/engine.c b/core/src/xmake/engine.c index 76886b326..cf361a8c5 100644 --- a/core/src/xmake/engine.c +++ b/core/src/xmake/engine.c @@ -39,6 +39,10 @@ #elif defined(TB_CONFIG_OS_LINUX) || defined(TB_CONFIG_OS_BSD) || defined(TB_CONFIG_OS_ANDROID) # include <unistd.h> #endif +#ifdef TB_CONFIG_OS_BSD +# include <sys/types.h> +# include <sys/sysctl.h> +#endif /* ////////////////////////////////////////////////////////////////////////////////////// * macros @@ -482,15 +486,20 @@ static tb_size_t xm_engine_get_program_file(xm_engine_t* engine, tb_char_t* path tb_uint32_t bufsize = (tb_uint32_t)maxn; if (!_NSGetExecutablePath(path, &bufsize)) ok = tb_true; +#elif defined(TB_CONFIG_OS_BSD) + tb_int_t mib[4]; mib[0] = CTL_KERN; mib[1] = KERN_PROC; mib[2] = KERN_PROC_PATHNAME; mib[3] = -1; + size_t size = maxn; + if (sysctl(mib, 4, path, &size, tb_null, 0) == 0 && size < maxn) + { + path[size] = '\0'; + ok = tb_true; + } #elif defined(XM_PROC_SELF_FILE) // get the executale file path as program directory ssize_t size = readlink(XM_PROC_SELF_FILE, path, (size_t)maxn); if (size > 0 && size < maxn) { - // end path[size] = '\0'; - - // ok ok = tb_true; } #endif |
