ref: 1eadc811d6caf591b73d236957617e80811e2637
parent: 49e3f29e0cea0d9a58effe3d2aee0679eca68fdc
author: Ori Bernstein <[email protected]>
date: Thu Jan 9 05:53:54 EST 2014
Fix execv on OSX
--- a/libstd/sys-osx.myr
+++ b/libstd/sys-osx.myr
@@ -541,9 +541,11 @@
var rusage
-> wait4(pid, loc, opt, &rusage)
}
+
const execv = {cmd, args
var cargs, i
+ /* doesn't just call execve() for efficiency's sake. */
cargs = (alloca(sizeof(byte#)*(args.len + 1)) castto(byte##))[:args.len]
for i = 0; i < args.len; i++
cargs[i] = cstring(args[i])
@@ -551,6 +553,34 @@
cargs[args.len] = 0 castto(byte#)
-> syscall(Sysexecve, cmd castto(byte#), cargs, __cenvp)
}
+
+const execve = {cmd, args, env
+ var cargs, cenv, i
+ var p
+
+ /* copy the args */
+ p = alloca((args.len + 1)*sizeof(byte#))
+ cargs = (p castto(byte##))[:args.len]
+ for i = 0; i < args.len; i++
+ cargs[i] = cstring(args[i])
+ ;;
+ cargs[args.len] = 0 castto(byte#)
+
+ /*
+ copy the env.
+ of course we fucking have to duplicate this code everywhere,
+ since we want to stack allocate...
+ */
+ p = alloca((env.len + 1)*sizeof(byte#))
+ cenv = (p castto(byte##))[:env.len]
+ for i = 0; i < env.len; i++
+ cenv[i] = cstring(env[i])
+ ;;
+ cenv[env.len] = 0 castto(byte#)
+
+ -> syscall(Sysexecve, cstring(cmd), p, cenv)
+}
+
/* fd manipulation */
const open = {path, opts, mode; -> syscall(Sysopen, cstring(path), opts, mode) castto(fd)}