From 44a012e3aa3e776b81b5fbc57674cbb9699d18fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C5=8Dshin?= Date: Sun, 7 Jan 2024 00:35:33 -0500 Subject: [PATCH] Get execfn the apple way https://github.com/opensource-apple/dyld/blob/master/src/dyld.cpp#L4789 --- ape/ape-m1.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/ape/ape-m1.c b/ape/ape-m1.c index 6b9127054..dcab1a105 100644 --- a/ape/ape-m1.c +++ b/ape/ape-m1.c @@ -953,13 +953,9 @@ int main(int argc, char **argv, char **envp) { M->lib.dlclose = dlclose; M->lib.dlerror = dlerror; - /* getenv("_") is close enough to at_execfn */ - execfn = argc > 0 ? argv[0] : 0; for (i = 0; envp[i]; ++i) { - if (envp[i][0] == '_' && envp[i][1] == '=') { - execfn = envp[i] + 2; - } } + execfn = GetEnv(envp + i + 1, "executable_path"); /* sneak the system five abi back out of args */ sp = (long *)(argv - 1); @@ -994,7 +990,7 @@ int main(int argc, char **argv, char **envp) { M->ps.literally = 0; if (*argv[0] == '-' && (shell = GetEnv(envp, "SHELL")) && !StrCmp(argv[0] + 1, BaseName(shell))) { - execfn = prog = shell; + prog = shell; } else { prog = (char *)sp[1]; }