aboutsummaryrefslogtreecommitdiff
path: root/std/os/linux.zig
diff options
context:
space:
mode:
authorAndrew Kelley <superjoe30@gmail.com>2017-04-02 20:44:04 -0400
committerAndrew Kelley <superjoe30@gmail.com>2017-04-02 20:44:04 -0400
commita1363b52278b68f59aa72adf985f11e6c1d02cf9 (patch)
tree3cfc069f75b16c549d1c6776bfac8cdce239d579 /std/os/linux.zig
parent640389bb2b04766e58e206c53ee2048c54534eb9 (diff)
downloadzig-a1363b52278b68f59aa72adf985f11e6c1d02cf9.tar.gz
zig-a1363b52278b68f59aa72adf985f11e6c1d02cf9.zip
proof of concept build system
see #204
Diffstat (limited to 'std/os/linux.zig')
-rw-r--r--std/os/linux.zig36
1 files changed, 2 insertions, 34 deletions
diff --git a/std/os/linux.zig b/std/os/linux.zig
index 8e1bf54aee..69a66505c5 100644
--- a/std/os/linux.zig
+++ b/std/os/linux.zig
@@ -261,40 +261,8 @@ pub fn dup2(old: i32, new: i32) -> usize {
arch.syscall2(arch.SYS_dup2, usize(old), usize(new))
}
-pub fn execve_c(path: &const u8, argv: &const ?&const u8, envp: &const ?&const u8) -> usize {
- arch.syscall3(arch.SYS_execve, path, argv, envp)
-}
-
-/// This function must allocate memory to add a null terminating bytes on path, each arg,
-/// and each environment variable line, as well as a null pointer after the arg list and
-/// environment variable list. We allocate stack memory since the process is about to get
-/// wiped anyway.
-pub fn execve(path: []const u8, argv: []const []const u8, envp: []const []const u8) -> usize {
- const path_buf = @alloca(u8, path.len + 1);
- @memcpy(&path_buf[0], &path[0], path.len);
- path_buf[path.len] = 0;
-
- const argv_buf = @alloca([]const ?&const u8, argv.len + 1);
- for (argv) |arg, i| {
- const arg_buf = @alloca(u8, arg.len + 1);
- @memcpy(&arg_buf[0], &arg[0], arg.len);
- arg_buf[arg.len] = 0;
-
- argv[i] = arg_buf;
- }
- argv_buf[argv.len] = null;
-
- const envp_buf = @alloca([]const ?&const u8, envp.len + 1);
- for (envp) |env, i| {
- const env_buf = @alloca(u8, env.len + 1);
- @memcpy(&env_buf[0], &env[0], env.len);
- env_buf[env.len] = 0;
-
- envp[i] = env_buf;
- }
- envp_buf[envp.len] = null;
-
- return execve_c(path_buf.ptr, argv_buf.ptr, envp_buf.ptr);
+pub fn execve(path: &const u8, argv: &const ?&const u8, envp: &const ?&const u8) -> usize {
+ arch.syscall3(arch.SYS_execve, usize(path), usize(argv), usize(envp))
}
pub fn fork() -> usize {