mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
os: add os.execvp/2
This commit is contained in:
parent
2795f929fa
commit
ef786f9a75
@ -22,6 +22,8 @@ fn C.fdopen(int, string) voidptr
|
|||||||
|
|
||||||
fn C.CopyFile(&u32, &u32, int) int
|
fn C.CopyFile(&u32, &u32, int) int
|
||||||
|
|
||||||
|
fn C.execvp(file charptr, argv &charptr) int
|
||||||
|
|
||||||
// fn C.proc_pidpath(int, byteptr, int) int
|
// fn C.proc_pidpath(int, byteptr, int) int
|
||||||
struct C.stat {
|
struct C.stat {
|
||||||
st_size int
|
st_size int
|
||||||
@ -866,3 +868,21 @@ pub fn create(path string) ?File {
|
|||||||
is_opened: true
|
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))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user