os: add os.execvp/2

pull/7659/head
Delyan Angelov 2020-12-28 17:55:50 +02:00
parent 2795f929fa
commit ef786f9a75
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED
1 changed files with 20 additions and 0 deletions

View File

@ -22,6 +22,8 @@ fn C.fdopen(int, string) voidptr
fn C.CopyFile(&u32, &u32, int) int
fn C.execvp(file charptr, argv &charptr) int
// fn C.proc_pidpath(int, byteptr, int) int
struct C.stat {
st_size int
@ -866,3 +868,21 @@ pub fn create(path string) ?File {
is_opened: true
}
}
// execvp - loads and executes a new child process, in place of the current process.
// The child process executable is located in `cmdpath`.
// The arguments, that will be passed to it are in `args`.
// NB: this function will NOT return when successfull, since
// the child process will take control over execution.
pub fn execvp(cmdpath string, args []string) ? {
mut cargs := []charptr{}
cargs << cmdpath.str
for i in 0 .. args.len {
cargs << args[i].str
}
cargs << charptr(0)
res := C.execvp(cmdpath.str, cargs.data)
if res == -1 {
return error(posix_get_error_msg(C.errno))
}
}