mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-08-07 02:10:27 +00:00
More reliable $prog.ape
Now it doesn't matter what argv `$prog.ape` is invoked with. We just get our executable path the apple way. https://github.com/opensource-apple/dyld/blob/master/src/dyld.cpp#L4789
This commit is contained in:
parent
b3fb6cff43
commit
9595dd140c
1 changed files with 5 additions and 7 deletions
12
ape/ape-m1.c
12
ape/ape-m1.c
|
@ -960,6 +960,7 @@ int main(int argc, char **argv, char **envp) {
|
||||||
execfn = envp[i] + 2;
|
execfn = envp[i] + 2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
prog = GetEnv(envp + i + 1, "executable_path");
|
||||||
|
|
||||||
/* sneak the system five abi back out of args */
|
/* sneak the system five abi back out of args */
|
||||||
sp = (long *)(argv - 1);
|
sp = (long *)(argv - 1);
|
||||||
|
@ -981,8 +982,8 @@ int main(int argc, char **argv, char **envp) {
|
||||||
sp = sp2;
|
sp = sp2;
|
||||||
|
|
||||||
/* interpret command line arguments */
|
/* interpret command line arguments */
|
||||||
if ((M->ps.indirect = argc > 0 ? GetIndirectOffset(argv[0]) : 0)) {
|
if ((M->ps.indirect = GetIndirectOffset(prog))) {
|
||||||
/* if argv[0] is $prog.ape, then we strip off the .ape and run
|
/* if called as $prog.ape, then strip off the .ape and run the
|
||||||
$prog. This allows you to use symlinks to trick the OS when
|
$prog. This allows you to use symlinks to trick the OS when
|
||||||
a native executable is required. For example, let's say you
|
a native executable is required. For example, let's say you
|
||||||
want to use the APE binary /opt/cosmos/bin/bash as a system
|
want to use the APE binary /opt/cosmos/bin/bash as a system
|
||||||
|
@ -992,11 +993,8 @@ int main(int argc, char **argv, char **envp) {
|
||||||
ln -sf /usr/local/bin/ape /opt/cosmos/bin/bash.ape
|
ln -sf /usr/local/bin/ape /opt/cosmos/bin/bash.ape
|
||||||
and then use #!/opt/cosmos/bin/bash.ape instead. */
|
and then use #!/opt/cosmos/bin/bash.ape instead. */
|
||||||
M->ps.literally = 0;
|
M->ps.literally = 0;
|
||||||
if (*argv[0] == '-' && (shell = GetEnv(envp, "SHELL")) &&
|
if (!execfn) {
|
||||||
!StrCmp(argv[0] + 1, BaseName(shell))) {
|
execfn = prog;
|
||||||
execfn = prog = shell;
|
|
||||||
} else {
|
|
||||||
prog = (char *)sp[1];
|
|
||||||
}
|
}
|
||||||
argc = sp[0];
|
argc = sp[0];
|
||||||
argv = (char **)(sp + 1);
|
argv = (char **)(sp + 1);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue