mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-06-27 23:08:31 +00:00
Reduce memory requirements for execve()
This commit is contained in:
parent
eaca5b3e81
commit
21e1023d28
7 changed files with 35 additions and 32 deletions
|
@ -25,15 +25,16 @@
|
|||
#include "libc/str/str.h"
|
||||
|
||||
int execve$sysv(const char *prog, char *const argv[], char *const envp[]) {
|
||||
size_t i, n;
|
||||
char **shargs, bash[PATH_MAX];
|
||||
size_t i;
|
||||
char **shargs;
|
||||
if (__execve$sysv(prog, argv, envp) != -1) return 0;
|
||||
if (errno != ENOEXEC) return -1;
|
||||
for (i = 0; argv[i];) ++i;
|
||||
shargs = alloca((i + 2) * sizeof(char *));
|
||||
memcpy(shargs + 2, argv + 1, i * sizeof(char *));
|
||||
shargs[0] = !IsFreebsd() ? _PATH_BSHELL
|
||||
: firstnonnull(commandv("bash", bash), _PATH_BSHELL);
|
||||
: firstnonnull(commandv("bash", alloca(PATH_MAX)),
|
||||
_PATH_BSHELL);
|
||||
shargs[1] = prog;
|
||||
return __execve$sysv(shargs[0], shargs, envp);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue