Looking for feedback.
I want to fork() and execv() but std.process.execv() does not like fork() due to heap allocation, so i built my own wrapper around std.posix.execve() which allocates some memory on the stack instead.
pub fn exec(argv: []const []const u8) !void {
const max_args = 256;
const max_arg_length = 2048;
var args: [max_args][max_arg_length:0]u8 = undefined;
var args_ptrs: [max_args:null]?[*:0]u8 = undefined;
var i: usize = 0;
for (argv) |arg| {
@memcpy(&args[i], arg.ptr);
args[i][arg.len] = 0; // add sentinel 0
args_ptrs[i] = &args[i];
i += 1;
}
args_ptrs[i] = null; // add sentinel null
return std.posix.execvpeZ_expandArg0(.no_expand, args_ptrs[0].?, &args_ptrs, &.{null});
}
is this a good way or are there more idiomatic ways?
