summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorSaikari <[email protected]>2026-02-02 14:36:27 +0300
committerSaikari <[email protected]>2026-02-02 14:36:27 +0300
commit7294865c853930c4a50009cf3be1f8d1b302198d (patch)
tree84d9b30ed51e2153e4088672cb8398b7a93982bd /core
parent93d38be02f934c234dd6e62f5fd6cfd25d4d59c4 (diff)
refactor: simplify ape program file handling in test cases and remove unused functions
Diffstat (limited to 'core')
-rw-r--r--core/src/xmake/engine.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/core/src/xmake/engine.c b/core/src/xmake/engine.c
index df5ae06be..7a76da7a1 100644
--- a/core/src/xmake/engine.c
+++ b/core/src/xmake/engine.c
@@ -874,6 +874,30 @@ static tb_bool_t xm_engine_get_program_file(xm_engine_t *engine, tb_char_t **arg
ssize_t size = readlink(XM_PROC_SELF_FILE, path, (size_t)maxn);
if (size > 0 && size < maxn) {
path[size] = '\0';
+#if defined(TB_CONFIG_OS_LINUX)
+ // fix /usr/bin/ape for cosmocc
+ if (size > 3 && !tb_strcmp(path + size - 3, "ape")) {
+ FILE* fp = fopen("/proc/self/cmdline", "rb");
+ if (fp) {
+ tb_char_t line[TB_PATH_MAXN * 2];
+ if (fread(line, 1, sizeof(line), fp) > 0) {
+ tb_char_t* p = line;
+ // if argv[0] is /usr/bin/ape, we use argv[1]
+ if (tb_strstr(p, "ape")) {
+ p += tb_strlen(p) + 1;
+ }
+ // get absolute path
+ if (p < line + sizeof(line) && *p) {
+ tb_char_t buf[TB_PATH_MAXN];
+ if (tb_path_absolute(p, buf, sizeof(buf))) {
+ tb_strlcpy(path, buf, maxn);
+ }
+ }
+ }
+ fclose(fp);
+ }
+ }
+#endif
ok = tb_true;
}
#elif defined(TB_CONFIG_OS_BSD) && defined(KERN_PROC_PATHNAME)